@@ -25,6 +25,8 @@ THIS SOFTWARE.
2525
2626local List = require 'pandoc.List'
2727
28+M = {}
29+
2830------------------------------------------------------------------------
2931-- Accessor objects
3032--
@@ -184,6 +186,18 @@ function AstElement:create_constructor(tag, fn, accessors)
184186 return constr
185187end
186188
189+--- Ensure a given object is an Inline element, or convert it into one.
190+local function ensureInlineList (x)
191+ if type(x) == string then
192+ return List:new{M.Str(x)}
193+ elseif x.tag then
194+ -- Lists are not tagged, but all elements are
195+ return List:new{x}
196+ else
197+ return x
198+ end
199+end
200+
187201------------------------------------------------------------------------
188202--- Pandoc Document
189203-- @section document
@@ -233,7 +247,7 @@ M.MetaBlocks = M.MetaValue:create_constructor(
233247-- @tparam {Inline,...} inlines inlines
234248M.MetaInlines = M.MetaValue:create_constructor(
235249 'MetaInlines',
236− function (content) return List:new(content) end
250+ function (content) return ensureInlineList(content) end
237251)
238252
239253--- Meta list
@@ -338,7 +352,7 @@ M.Div = M.Block:create_constructor(
338352M.Header = M.Block:create_constructor(
339353 "Header",
340354 function(level, content, attr)
341− return {c = {level, attr or M.Attr(), content}}
355+ return {c = {level, attr or M.Attr(), ensureInlineList(content)}}
342356 end,
343357 {"level", {"identifier", "classes", "attributes"}, "content"}
344358)
@@ -389,7 +403,7 @@ M.OrderedList = M.Block:create_constructor(
389403-- @treturn Block paragraph element
390404M.Para = M.Block:create_constructor(
391405 "Para",
392− function(content) return {c = List:new(content)} end,
406+ function(content) return {c = ensureInlineList(content)} end,
393407 "content"
394408)
395409
@@ -399,7 +413,7 @@ M.Para = M.Block:create_constructor(
399413-- @treturn Block plain element
400414M.Plain = M.Block:create_constructor(
401415 "Plain",
402− function(content) return {c = List:new(content)} end,
416+ function(content) return {c = ensureInlineList(content)} end,
403417 "content"
404418)
405419
@@ -427,7 +441,7 @@ M.Table = M.Block:create_constructor(
427441 function(caption, aligns, widths, headers, rows)
428442 return {
429443 c = {
430− List:new(caption),
444+ ensureInlineList(caption),
431445 List:new(aligns),
432446 List:new(widths),
433447 List:new(headers),
@@ -454,7 +468,7 @@ M.Inline = AstElement:make_subtype'Inline'
454468M.Cite = M.Inline:create_constructor(
455469 "Cite",
456470 function(content, citations)
457− return {c = {List:new(citations), List:new(content)}}
471+ return {c = {List:new(citations), ensureInlineList(content)}}
458472 end,
459473 {"citations", "content"}
460474)
@@ -476,7 +490,7 @@ M.Code = M.Inline:create_constructor(
476490-- @treturn Inline emphasis element
477491M.Emph = M.Inline:create_constructor(
478492 "Emph",
479− function(content) return {c = List:new(content)} end,
493+ function(content) return {c = ensureInlineList(content)} end,
480494 "content"
481495)
482496
@@ -492,7 +506,7 @@ M.Image = M.Inline:create_constructor(
492506 function(caption, src, title, attr)
493507 title = title or ""
494508 attr = attr or M.Attr()
495− return {c = {attr, List:new(caption), {src, title}}}
509+ return {c = {attr, ensureInlineList(caption), {src, title}}}
496510 end,
497511 {{"identifier", "classes", "attributes"}, "caption", {"src", "title"}}
498512)
@@ -517,7 +531,7 @@ M.Link = M.Inline:create_constructor(
517531 function(content, target, title, attr)
518532 title = title or ""
519533 attr = attr or M.Attr()
520− return {c = {attr, List:new(content), {target, title}}}
534+ return {c = {attr, ensureInlineList(content), {target, title}}}
521535 end,
522536 {{"identifier", "classes", "attributes"}, "content", {"target", "title"}}
523537)
@@ -569,7 +583,7 @@ M.Note = M.Inline:create_constructor(
569583-- @treturn Inline quoted element
570584M.Quoted = M.Inline:create_constructor(
571585 "Quoted",
572− function(quotetype, content) return {c = {quotetype, List:new(content)}} end,
586+ function(quotetype, content) return {c = {quotetype, ensureInlineList(content)}} end,
573587 {"quotetype", "content"}
574588)
575589--- Creates a single-quoted inline element (DEPRECATED).
@@ -610,7 +624,7 @@ M.RawInline = M.Inline:create_constructor(
610624-- @treturn Inline smallcaps element
611625M.SmallCaps = M.Inline:create_constructor(
612626 "SmallCaps",
613− function(content) return {c = List:new(content)} end,
627+ function(content) return {c = ensureInlineList(content)} end,
614628 "content"
615629)
616630
@@ -638,7 +652,7 @@ M.Space = M.Inline:create_constructor(
638652M.Span = M.Inline:create_constructor(
639653 "Span",
640654 function(content, attr)
641− return {c = {attr or M.Attr(), List:new(content)}}
655+ return {c = {attr or M.Attr(), ensureInlineList(content)}}
642656 end,
643657 {{"identifier", "classes", "attributes"}, "content"}
644658)
@@ -659,7 +673,7 @@ M.Str = M.Inline:create_constructor(
659673-- @treturn Inline strikeout element
660674M.Strikeout = M.Inline:create_constructor(
661675 "Strikeout",
662− function(content) return {c = List:new(content)} end,
676+ function(content) return {c = ensureInlineList(content)} end,
663677 "content"
664678)
665679
@@ -669,7 +683,7 @@ M.Strikeout = M.Inline:create_constructor(
669683-- @treturn Inline strong element
670684M.Strong = M.Inline:create_constructor(
671685 "Strong",
672− function(content) return {c = List:new(content)} end,
686+ function(content) return {c = ensureInlineList(content)} end,
673687 "content"
674688)
675689
@@ -679,7 +693,7 @@ M.Strong = M.Inline:create_constructor(
679693-- @treturn Inline subscript element
680694M.Subscript = M.Inline:create_constructor(
681695 "Subscript",
682− function(content) return {c = List:new(content)} end,
696+ function(content) return {c = ensureInlineList(content)} end,
683697 "content"
684698)
685699
@@ -689,7 +703,7 @@ M.Subscript = M.Inline:create_constructor(
689703-- @treturn Inline strong element
690704M.Superscript = M.Inline:create_constructor(
691705 "Superscript",
692− function(content) return {c = List:new(content)} end,
706+ function(content) return {c = ensureInlineList(content)} end,
693707 "content"
694708)
695709