Skip to content

Commit

Permalink
Merge pull request #11540 from tarleb/jog-as-default
Browse files Browse the repository at this point in the history
Use `jog` to as the traversal method in filters
  • Loading branch information
cscheid authored Jan 17, 2025
2 parents c2deaa2 + 62be5a9 commit 45fc32a
Show file tree
Hide file tree
Showing 18 changed files with 736 additions and 184 deletions.
18 changes: 16 additions & 2 deletions src/resources/filters/ast/customnodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function is_regular_node(node, name)
return node
end

function run_emulated_filter(doc, filter)
function run_emulated_filter(doc, filter, traverse)
if doc == nil then
return nil
end
Expand Down Expand Up @@ -73,7 +73,21 @@ function run_emulated_filter(doc, filter)
-- luacov: enable
end
end
return node:walk(filter_param)

local old_traverse = _quarto.traverser
if traverser == nil or traverser == 'pandoc' or traverser == 'walk' then
_quarto.traverser = _quarto.utils.walk
elseif traverser == 'jog' then
_quarto.traverser = _quarto.modules.jog
elseif type(traverser) == 'function' then
_quarto.traverser = traverser
else
warn('Unknown traverse method: ' .. tostring(traverse))
end
local result = _quarto.traverser(node, filter_param)
_quarto.traverse = old_traverse

return result
end

-- performance: if filter is empty, do nothing
Expand Down
5 changes: 4 additions & 1 deletion src/resources/filters/ast/emulatedfilter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ inject_user_filters_at_entry_points = function(filter_list)
end
local filter = {
name = entry_point .. "-user-" .. tostring(entry_point_counts[entry_point]),
-- The filter might not work as expected when doing a non-lazy jog, so
-- make sure it is processed with the default 'walk' function.
traverser = 'walk',
}
if is_many_filters then
filter.filters = wrapped
Expand All @@ -76,4 +79,4 @@ inject_user_filters_at_entry_points = function(filter_list)
end
table.insert(filter_list, index, filter)
end
end
end
4 changes: 2 additions & 2 deletions src/resources/filters/ast/runemulation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ local function run_emulated_filter_chain(doc, filters, afterFilterPass, profilin
print(pandoc.write(doc, "native"))
else
_quarto.ast._current_doc = doc
doc = run_emulated_filter(doc, v.filter)
doc = run_emulated_filter(doc, v.filter, v.traverser)
ensure_vault(doc)

add_trace(doc, v.name)
Expand Down Expand Up @@ -204,4 +204,4 @@ function run_as_extended_ast(specTable)
end

return pandocFilterList
end
end
4 changes: 2 additions & 2 deletions src/resources/filters/common/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ end
-- we often wrap a table in a div, unwrap it
function tableFromLayoutCell(cell)
local tbl
cell:walk({
_quarto.traverser(cell, {
Table = function(t)
tbl = t
end
Expand Down Expand Up @@ -106,4 +106,4 @@ function asLatexSize(size, macro)
else
return size
end
end
end
6 changes: 3 additions & 3 deletions src/resources/filters/common/pandoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ function string_to_quarto_ast_blocks(text, opts)

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

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

function string_to_quarto_ast_inlines(text, sep)
return pandoc.utils.blocks_to_inlines(string_to_quarto_ast_blocks(text), sep)
end
end
6 changes: 3 additions & 3 deletions src/resources/filters/common/wrapped-filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function makeWrappedJsonFilter(scriptFile, filterHandler)
path = quarto.utils.resolve_path_relative_to_document(scriptFile)
local custom_node_map = {}
local has_custom_nodes = false
doc = doc:walk({
doc = _quarto.traverser(doc, {
-- FIXME: This is broken with new AST. Needs to go through Custom node instead.
RawInline = function(raw)
local custom_node, t, kind = _quarto.ast.resolve_custom_data(raw)
Expand Down Expand Up @@ -130,7 +130,7 @@ function makeWrappedJsonFilter(scriptFile, filterHandler)
return nil
end
if has_custom_nodes then
doc:walk({
_quarto.traverser(doc, {
Meta = function(meta)
_quarto.ast.reset_custom_tbl(meta["quarto-custom-nodes"])
end
Expand Down Expand Up @@ -250,4 +250,4 @@ function filterSeq(filters)
return result
end
}
end
end
Loading

0 comments on commit 45fc32a

Please sign in to comment.