Skip to content

Commit 59b30ae

Browse files
committed
Force use of pandoc walk for some filters
1 parent 58f522d commit 59b30ae

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

src/resources/filters/ast/customnodes.lua

Lines changed: 5 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, force_use_walk)
4545
if doc == nil then
4646
return nil
4747
end
@@ -73,7 +73,10 @@ function run_emulated_filter(doc, filter)
7373
-- luacov: enable
7474
end
7575
end
76-
return _quarto.modules.jog(node, filter_param)
76+
_QUARTO_USE_WALK = force_use_walk
77+
local result = _quarto.modules.jog(node, filter_param)
78+
_QUARTO_USE_WALK = false
79+
return result
7780
end
7881

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

src/resources/filters/ast/emulatedfilter.lua

Lines changed: 3 additions & 0 deletions
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+
force_pandoc_walk = true,
7174
}
7275
if is_many_filters then
7376
filter.filters = wrapped

src/resources/filters/ast/runemulation.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ 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+
83+
doc = run_emulated_filter(doc, v.filter, v.force_pandoc_walk)
84+
8385
ensure_vault(doc)
8486

8587
add_trace(doc, v.name)
@@ -204,4 +206,4 @@ function run_as_extended_ast(specTable)
204206
end
205207

206208
return pandocFilterList
207-
end
209+
end

src/resources/filters/main.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ local quarto_post_filters = {
374374
{ name = "post-ojs", filter = ojs() },
375375

376376
{ name = "post-render-pandoc3-figure", filter = render_pandoc3_figure(),
377-
flags = { "has_pandoc3_figure" } },
377+
flags = { "has_pandoc3_figure" }, force_pandoc_walk = true },
378378

379379
-- extensible rendering
380380
{ name = "post-render_extended_nodes", filter = render_extended_nodes() },
@@ -425,6 +425,10 @@ local quarto_layout_filters = {
425425
{ name = "layout-panels", filter = layout_panels() },
426426
{ name = "post-fold-code-and-lift-codeblocks-from-floats", filter = fold_code_and_lift_codeblocks() },
427427
}
428+
quarto_layout_filters = pandoc.List.map(quarto_layout_filters, function (f)
429+
f.force_pandoc_walk = true
430+
return f
431+
end)
428432

429433
local quarto_crossref_filters = {
430434

@@ -435,7 +439,8 @@ local quarto_crossref_filters = {
435439
filter = crossref_preprocess_theorems(),
436440
flags = { "has_theorem_refs" } },
437441

438-
{ name = "crossref-combineFilters", filter = combineFilters({
442+
{ name = "crossref-combineFilters", force_pandoc_walk = true,
443+
filter = combineFilters({
439444
file_metadata(),
440445
qmd(),
441446
sections(),

src/resources/filters/modules/jog.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ local function jog(element, filter)
255255
end
256256
end
257257

258+
if _QUARTO_USE_WALK then
259+
return element:walk(filter)
260+
end
261+
258262
-- Create and call traversal function
259263
local jog_internal = make_jogger(filter, context)
260264
return jog_internal(element)

src/resources/filters/normalize/astpipeline.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ function quarto_ast_pipeline()
3535
code_filename(),
3636
normalize_fixup_data_uri_image_extension(),
3737
warn_on_stray_triple_colons(),
38-
})
38+
}),
39+
force_pandoc_walk = true,
3940
},
4041
{
4142
name = "normalize-combine-2",
@@ -44,6 +45,7 @@ function quarto_ast_pipeline()
4445
parse_floatreftargets(),
4546
parse_blockreftargets()
4647
}),
48+
force_pandoc_walk = true,
4749
},
4850
{
4951
name = "normalize-3",

0 commit comments

Comments
 (0)