Skip to content

Commit 45fc32a

Browse files
authored
Merge pull request #11540 from tarleb/jog-as-default
Use `jog` to as the traversal method in filters
2 parents c2deaa2 + 62be5a9 commit 45fc32a

File tree

18 files changed

+736
-184
lines changed

18 files changed

+736
-184
lines changed

src/resources/filters/ast/customnodes.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function is_regular_node(node, name)
4141
return node
4242
end
4343

44-
function run_emulated_filter(doc, filter)
44+
function run_emulated_filter(doc, filter, traverse)
4545
if doc == nil then
4646
return nil
4747
end
@@ -73,7 +73,21 @@ function run_emulated_filter(doc, filter)
7373
-- luacov: enable
7474
end
7575
end
76-
return node:walk(filter_param)
76+
77+
local old_traverse = _quarto.traverser
78+
if traverser == nil or traverser == 'pandoc' or traverser == 'walk' then
79+
_quarto.traverser = _quarto.utils.walk
80+
elseif traverser == 'jog' then
81+
_quarto.traverser = _quarto.modules.jog
82+
elseif type(traverser) == 'function' then
83+
_quarto.traverser = traverser
84+
else
85+
warn('Unknown traverse method: ' .. tostring(traverse))
86+
end
87+
local result = _quarto.traverser(node, filter_param)
88+
_quarto.traverse = old_traverse
89+
90+
return result
7791
end
7892

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

src/resources/filters/ast/emulatedfilter.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ inject_user_filters_at_entry_points = function(filter_list)
6868
end
6969
local filter = {
7070
name = entry_point .. "-user-" .. tostring(entry_point_counts[entry_point]),
71+
-- The filter might not work as expected when doing a non-lazy jog, so
72+
-- make sure it is processed with the default 'walk' function.
73+
traverser = 'walk',
7174
}
7275
if is_many_filters then
7376
filter.filters = wrapped
@@ -76,4 +79,4 @@ inject_user_filters_at_entry_points = function(filter_list)
7679
end
7780
table.insert(filter_list, index, filter)
7881
end
79-
end
82+
end

src/resources/filters/ast/runemulation.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ local function run_emulated_filter_chain(doc, filters, afterFilterPass, profilin
7979
print(pandoc.write(doc, "native"))
8080
else
8181
_quarto.ast._current_doc = doc
82-
doc = run_emulated_filter(doc, v.filter)
82+
doc = run_emulated_filter(doc, v.filter, v.traverser)
8383
ensure_vault(doc)
8484

8585
add_trace(doc, v.name)
@@ -204,4 +204,4 @@ function run_as_extended_ast(specTable)
204204
end
205205

206206
return pandocFilterList
207-
end
207+
end

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

0 commit comments

Comments
 (0)