Skip to content

Commit 5135446

Browse files
committed
Rely less on pandoc's type implicit conversions
1 parent f3b90a3 commit 5135446

File tree

9 files changed

+22
-17
lines changed

9 files changed

+22
-17
lines changed

src/resources/filters/ast/customnodes.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,15 @@ _quarto.ast = {
386386
if index > #node.content then
387387
_quarto.ast.grow_scaffold(node, index)
388388
end
389-
local pt = pandoc.utils.type(value)
390-
if pt == "Block" or pt == "Inline" then
391-
node.content[index].content = {value}
389+
local pt = pandoc.utils.type(node.content[index])
390+
if pt == "Block" then
391+
node.content[index].content =
392+
_quarto.modules.attribcheck.ensure_blocks(value)
393+
elseif pt == "Inline" then
394+
node.content[index].content =
395+
_quarto.modules.attribcheck.ensure_inlines(value)
392396
else
397+
warn('Cannot handle type ' .. pt)
393398
node.content[index].content = value
394399
end
395400
end

src/resources/filters/crossref/equations.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function process_equations(blockEl)
2020
end
2121

2222
local mathInlines = nil
23-
local targetInlines = pandoc.List()
23+
local targetInlines = pandoc.Inlines{}
2424

2525
for i, el in ipairs(inlines) do
2626

src/resources/filters/crossref/preprocess.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function crossref_mark_subfloats()
77
return {
88
traverse = "topdown",
99
FloatRefTarget = function(float)
10-
float.content = _quarto.ast.walk(float.content, {
10+
float.content = _quarto.ast.walk(float.content or pandoc.Blocks{}, {
1111
FloatRefTarget = function(subfloat)
1212
float.has_subfloats = true
1313
crossref.subfloats[subfloat.identifier] = {

src/resources/filters/customnodes/floatreftarget.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ function float_reftarget_render_html_figure(float)
767767
local float_content = pandoc.Div(_quarto.ast.walk(float.content, {
768768
-- strip image captions
769769
Image = function(image)
770-
image.caption = {}
770+
image.caption = pandoc.Inlines{}
771771
return image
772772
end
773773
}) or pandoc.Div({})) -- this should never happen but the lua analyzer doesn't know it
@@ -1098,4 +1098,4 @@ end, function(float)
10981098
return pandoc.Para({im})
10991099
end)
11001100

1101-
global_table_guid_id = 0
1101+
global_table_guid_id = 0

src/resources/filters/customnodes/shortcodes.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ _quarto.ast.add_handler({
1111
kind = "Inline",
1212

1313
parse = function(span)
14-
local inner_content = pandoc.List({})
14+
local inner_content = pandoc.Inlines({})
1515

1616
span.content = span.content:filter(function(el)
1717
return el.t == "Span"
@@ -78,9 +78,9 @@ _quarto.ast.add_handler({
7878
end
7979

8080
local node = _quarto.ast.create_custom_node_scaffold("Shortcode", "Inline")
81-
node.content = inner_content:map(function(el)
82-
return pandoc.Span({el})
83-
end)
81+
node.content = pandoc.Inlines(inner_content:map(function(el)
82+
return pandoc.Span({el})
83+
end))
8484
local tbl = {
8585
__quarto_custom_node = node,
8686
name = name,

src/resources/filters/layout/html.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function renderHtmlFigure(el, render)
190190
end)
191191

192192
-- remove identifier (it is now on the div)
193-
el.identifier = ""
193+
el.attr.identifier = ""
194194

195195
if not figureDiv.classes:find_if(function(str) return str:match("quarto%-figure%-.+") end) then
196196
-- apply standalone figure css if not already set

src/resources/filters/quarto-post/foldcode.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function fold_code_and_lift_codeblocks()
6565
local prev_annotated_code_block_scaffold = nil
6666
local prev_annotated_code_block = nil
6767
-- ok to lift codeblocks
68-
float.content = _quarto.ast.walk(float.content, {
68+
float.content = _quarto.ast.walk(float.content or pandoc.Blocks{}, {
6969
traverse = "topdown",
7070
DecoratedCodeBlock = function(block)
7171
-- defer the folding of code blocks to the DecoratedCodeBlock renderer

src/resources/filters/quarto-pre/code-annotation.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ function code_annotations()
310310
-- if code annotations is false, then shut it down
311311
if codeAnnotations ~= false then
312312

313-
local outputs = pandoc.List()
313+
local outputs = pandoc.Blocks{}
314314

315315
-- annotations[annotation-number] = {list of line numbers}
316316
local pendingAnnotations = nil

src/resources/filters/quarto-pre/parsefiguredivs.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ function parse_floatreftargets()
458458
fig_attr.classes:insert(v)
459459
end
460460
end
461-
image.caption = {}
461+
image.caption = pandoc.Inlines{}
462462
return image
463463
end
464464
}) or fig.content[1] -- this shouldn't be needed but the lua analyzer doesn't know it
@@ -602,7 +602,7 @@ function parse_floatreftargets()
602602
if img.identifier == "" then
603603
local caption = img.caption
604604
if #caption > 0 then
605-
img.caption = nil
605+
img.caption = pandoc.Inlines{}
606606
return pandoc.Figure(link, { long = { caption } })
607607
else
608608
return nil
@@ -819,4 +819,4 @@ function forward_cell_subcaps()
819819
return div
820820
end
821821
}
822-
end
822+
end

0 commit comments

Comments
 (0)