Skip to content

Commit 056c8ab

Browse files
committed
Store traversal function in _quarto.traverser
1 parent 89db5f2 commit 056c8ab

File tree

10 files changed

+42
-29
lines changed

10 files changed

+42
-29
lines changed

src/resources/filters/ast/customnodes.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ function run_emulated_filter(doc, filter)
7373
-- luacov: enable
7474
end
7575
end
76-
return node:walk(filter_param)
76+
local result = node:walk(filter_param)
77+
return result
7778
end
7879

7980
-- performance: if filter is empty, do nothing

src/resources/filters/common/layout.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ end
5656
-- we often wrap a table in a div, unwrap it
5757
function tableFromLayoutCell(cell)
5858
local tbl
59-
cell:walk({
59+
_quarto.traverser(cell, {
6060
Table = function(t)
6161
tbl = t
6262
end
@@ -106,4 +106,4 @@ function asLatexSize(size, macro)
106106
else
107107
return size
108108
end
109-
end
109+
end

src/resources/filters/common/pandoc.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,14 @@ function string_to_quarto_ast_blocks(text, opts)
216216

217217
-- run the whole normalization pipeline here to get extended AST nodes, etc.
218218
for _, filter in ipairs(quarto_ast_pipeline()) do
219-
doc = doc:walk(filter.filter)
219+
doc = _quarto.traverser(doc, filter.filter)
220220
end
221221

222222
-- compute flags so we don't skip filters that depend on them
223-
doc:walk(compute_flags())
223+
_quarto.traverser(doc, compute_flags())
224224
return doc.blocks
225225
end
226226

227227
function string_to_quarto_ast_inlines(text, sep)
228228
return pandoc.utils.blocks_to_inlines(string_to_quarto_ast_blocks(text), sep)
229-
end
229+
end

src/resources/filters/common/wrapped-filter.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function makeWrappedJsonFilter(scriptFile, filterHandler)
9797
path = quarto.utils.resolve_path_relative_to_document(scriptFile)
9898
local custom_node_map = {}
9999
local has_custom_nodes = false
100-
doc = doc:walk({
100+
doc = _quarto.traverser(doc, {
101101
-- FIXME: This is broken with new AST. Needs to go through Custom node instead.
102102
RawInline = function(raw)
103103
local custom_node, t, kind = _quarto.ast.resolve_custom_data(raw)
@@ -130,7 +130,7 @@ function makeWrappedJsonFilter(scriptFile, filterHandler)
130130
return nil
131131
end
132132
if has_custom_nodes then
133-
doc:walk({
133+
_quarto.traverser(doc, {
134134
Meta = function(meta)
135135
_quarto.ast.reset_custom_tbl(meta["quarto-custom-nodes"])
136136
end
@@ -250,4 +250,4 @@ function filterSeq(filters)
250250
return result
251251
end
252252
}
253-
end
253+
end

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ local license = require 'modules/license'
88
local function clean (inlines)
99
-- this is in post, so it's after render, so we don't need to worry about
1010
-- custom ast nodes
11-
return inlines:walk {
12-
Note = function (_) return {} end,
11+
return _quarto.traverser(inlines, {
12+
traverse = 'topdown',
13+
Note = function (_) return {}, false end,
1314
Link = function (link) return link.content end,
14-
}
15+
})
1516
end
1617

1718
--- Creates an Inlines singleton containing the raw LaTeX.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function delink()
1919
-- find links and transform them to spans
2020
-- this is in post, so it's after render, so we don't need to worry about
2121
-- custom ast nodes
22-
return pandoc.walk_block(div, {
22+
return _quarto.traverser(div, {
2323
Link = function(link)
2424
return pandoc.Span(link.content)
2525
end

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ function render_latex()
407407
end,
408408
Note = function(el)
409409
tappend(noteContents, {el.content})
410-
el.content:walk({
410+
_quarto.traverser(el.content, {
411411
CodeBlock = function(el)
412412
hasVerbatimInNotes = true
413413
end
@@ -570,19 +570,7 @@ function render_latex_fixups()
570570
return emit_color("{rgb}{0,0,0}")
571571
end
572572
end
573-
return {
574-
Meta = function(meta)
575-
if not need_inject then
576-
return
577-
end
578-
metaInjectLatex(meta, function(inject)
579-
for v, i in pairs(emitted_colors) do
580-
local def = "\\definecolor{QuartoInternalColor" .. i .. "}" .. v
581-
inject(def)
582-
end
583-
end)
584-
return meta
585-
end,
573+
return {{
586574
RawBlock = function(raw)
587575
if _quarto.format.isRawLatex(raw) then
588576
local long_table_match = _quarto.modules.patterns.match_all_in_table(_quarto.patterns.latexLongtablePattern)
@@ -615,5 +603,18 @@ function render_latex_fixups()
615603
return pandoc.RawBlock('latex', table.concat(new_lines, "\n"))
616604
end
617605
end
618-
}
606+
}, {
607+
Meta = function(meta)
608+
if not need_inject then
609+
return
610+
end
611+
metaInjectLatex(meta, function(inject)
612+
for v, i in pairs(emitted_colors) do
613+
local def = "\\definecolor{QuartoInternalColor" .. i .. "}" .. v
614+
inject(def)
615+
end
616+
end)
617+
return meta
618+
end,
619+
}}
619620
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function server_shiny()
6767
-- blocks.)
6868
local context = nil
6969

70-
local res = pandoc.walk_block(divEl, {
70+
local res = _quarto.traverser(divEl, {
7171
CodeBlock = function(el)
7272
if el.attr.classes:includes("python") and el.attr.classes:includes("cell-code") then
7373

src/resources/pandoc/datadir/_utils.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,14 @@ local function is_empty_node (node)
599599
end
600600
end
601601

602+
--- Call the node's walk method with the given filters.
603+
-- @param node a pandoc AST node
604+
-- @param filter table with filter functions
605+
local function walk(node, filter)
606+
quarto_assert(node and node.walk)
607+
return node:walk(filter)
608+
end
609+
602610
return {
603611
dump = dump,
604612
type = get_type,
@@ -611,6 +619,7 @@ return {
611619
as_blocks = as_blocks,
612620
is_empty_node = is_empty_node,
613621
match = match,
622+
walk = walk,
614623
add_to_blocks = function(blocks, block)
615624
if pandoc.utils.type(blocks) ~= "Blocks" then
616625
fatal("add_to_blocks: invalid type " .. pandoc.utils.type(blocks))

src/resources/pandoc/datadir/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,7 @@ _quarto = {
18821882
latexTablePatterns = latexTablePatterns,
18831883
latexCaptionPattern = latexCaptionPattern_table
18841884
},
1885+
traverser = utils.walk,
18851886
utils = utils,
18861887
withScriptFile = function(file, callback)
18871888
table.insert(scriptFile, file)

0 commit comments

Comments
 (0)