Lua: allow single elements as singleton MetaBlocks/MetaInlines

Single elements should always be treated as singleton lists in the Lua
subsystem.
This commit is contained in:
Albert Krewinkel 2021-11-24 16:41:52 +01:00
parent 79e6f8db13
commit a8638894ab
No known key found for this signature in database
GPG key ID: 388DC0B21F631124
2 changed files with 22 additions and 1 deletions

View file

@ -247,6 +247,9 @@ peekMetaValue = retrieving "MetaValue $ " . \idx -> do
optional (LuaUtil.getTag idx) >>= \case
Just tag -> peekTagged tag
Nothing -> peekUntagged
Lua.TypeUserdata -> -- Allow singleton Inline or Block elements
(MetaInlines . (:[]) <$!> peekInline idx) <|>
(MetaBlocks . (:[]) <$!> peekBlock idx)
_ -> failPeek "could not get meta value"
typeBlock :: LuaError e => DocumentedType e Block

View file

@ -735,7 +735,25 @@ return {
assert.are_equal((pandoc.MetaMap{}).tag, (pandoc.MetaMap{}).t)
assert.are_equal((pandoc.MetaInlines{}).tag, (pandoc.MetaInlines{}).t)
assert.are_equal((pandoc.MetaBlocks{}).tag, (pandoc.MetaBlocks{}).t)
end)
end),
},
group 'Meta' {
test('inline list is treated as MetaInlines', function ()
local meta = pandoc.Pandoc({}, {test = {pandoc.Emph 'check'}}).meta
assert.are_same(meta.test, {pandoc.Emph{pandoc.Str 'check'}})
end),
test('inline element is treated as MetaInlines singleton', function ()
local meta = pandoc.Pandoc({}, {test = pandoc.Emph 'check'}).meta
assert.are_same(meta.test, {pandoc.Emph{pandoc.Str 'check'}})
end),
test('block list is treated as MetaBlocks', function ()
local meta = pandoc.Pandoc({}, {test = {pandoc.Plain 'check'}}).meta
assert.are_same(meta.test, {pandoc.Plain{pandoc.Str 'check'}})
end),
test('block element is treated as MetaBlocks singleton', function ()
local meta = pandoc.Pandoc({}, {test = pandoc.Plain 'check'}).meta
assert.are_same(meta.test, {pandoc.Plain{pandoc.Str 'check'}})
end),
},
group 'Other types' {
group 'Citation' {