Skip to content

Commit

Permalink
Lua: support more elements as input to pandoc.utils.stringify.
Browse files Browse the repository at this point in the history
Elements of type Caption, Cell, TableHead, and TableFoot can now be
stringified.

Fixes: #10450
  • Loading branch information
tarleb committed Dec 10, 2024
1 parent 64f45fe commit a084731
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pandoc-lua-engine/src/Text/Pandoc/Lua/Module/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions pandoc-lua-engine/test/lua/module/pandoc-utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ',
Expand Down

0 comments on commit a084731

Please sign in to comment.