From a0847310700d8c706203471c871a6805c221092c Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 10 Dec 2024 11:36:00 +0100 Subject: [PATCH] Lua: support more elements as input to `pandoc.utils.stringify`. Elements of type Caption, Cell, TableHead, and TableFoot can now be stringified. Fixes: #10450 --- .../src/Text/Pandoc/Lua/Module/Utils.hs | 4 ++++ .../test/lua/module/pandoc-utils.lua | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Utils.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Utils.hs index fb0f3ee74c8d..a19f353b581d 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Utils.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Utils.hs @@ -316,7 +316,11 @@ stringify = defun "stringify" [ (fmap Shared.stringify . peekPandoc) , (fmap Shared.stringify . peekInline) , (fmap Shared.stringify . peekBlock) + , (fmap Shared.stringify . peekCaption) + , (fmap Shared.stringify . peekCell) , (fmap Shared.stringify . peekCitation) + , (fmap Shared.stringify . peekTableHead) + , (fmap Shared.stringify . peekTableFoot) , (fmap stringifyMetaValue . peekMetaValue) , (fmap (const "") . peekAttr) , (fmap (const "") . peekListAttributes) diff --git a/pandoc-lua-engine/test/lua/module/pandoc-utils.lua b/pandoc-lua-engine/test/lua/module/pandoc-utils.lua index 573a5987ae5d..9694cd57bb1d 100644 --- a/pandoc-lua-engine/test/lua/module/pandoc-utils.lua +++ b/pandoc-lua-engine/test/lua/module/pandoc-utils.lua @@ -223,6 +223,22 @@ return { local inlines = pandoc.Inlines{pandoc.Str 'a', pandoc.Subscript('b')} assert.are_equal('ab', utils.stringify(inlines)) end), + test('Caption', function () + local capt = pandoc.Caption(pandoc.Para{pandoc.Str 'a', pandoc.Emph('b')}) + assert.are_equal('ab', utils.stringify(capt)) + end), + test('Cell', function () + local cell = pandoc.Cell(pandoc.Para{pandoc.Str 'a', pandoc.Emph('b')}) + assert.are_equal('ab', utils.stringify(cell)) + end), + test('TableFoot', function () + local tf = pandoc.TableFoot{pandoc.Row{pandoc.Cell{pandoc.Plain "x y"}}} + assert.are_equal('x y', utils.stringify(tf)) + end), + test('TableHead', function () + local th = pandoc.TableHead{pandoc.Row{pandoc.Cell{pandoc.Plain "head1"}}} + assert.are_equal('head1', utils.stringify(th)) + end), test('Meta', function () local meta = pandoc.Meta{ a = pandoc.Inlines 'funny and ',