Skip to content

Commit f4f4d9e

Browse files
authored
Lua: ensure we're using Custom-aware walkers everywhere (#4622)
* Lua filters - :walk() must be _quarto.ast.walk() for custom AST nodes * smoke test
1 parent bd614a0 commit f4f4d9e

File tree

19 files changed

+56
-30
lines changed

19 files changed

+56
-30
lines changed

src/resources/filters/ast/customnodes.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function resolve_custom_node(node)
1717
end
1818
end
1919

20-
function run_emulated_filter(doc, filter)
20+
function run_emulated_filter(doc, filter, top_level)
2121
local wrapped_filter = {}
2222
for k, v in pairs(filter) do
2323
wrapped_filter[k] = v
@@ -132,7 +132,7 @@ function run_emulated_filter(doc, filter)
132132
end
133133

134134
local result = doc:walk(wrapped_filter)
135-
if filter._filter_name ~= nil then
135+
if top_level and filter._filter_name ~= nil then
136136
add_trace(result, filter._filter_name)
137137
end
138138
return result

src/resources/filters/ast/runemulation.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local function run_emulated_filter_chain(doc, filters, afterFilterPass)
88
if tisarray(filters) then
99
for i, v in ipairs(filters) do
1010
local function callback()
11-
doc = run_emulated_filter(doc, v)
11+
doc = run_emulated_filter(doc, v, true)
1212
end
1313
if v.scriptFile then
1414
_quarto.withScriptFile(v.scriptFile, callback)
@@ -20,7 +20,7 @@ local function run_emulated_filter_chain(doc, filters, afterFilterPass)
2020
end
2121
end
2222
elseif type(filters) == "table" then
23-
doc = run_emulated_filter(doc, filters)
23+
doc = run_emulated_filter(doc, filters, true)
2424
if afterFilterPass then
2525
afterFilterPass()
2626
end

src/resources/filters/common/refs.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function hasSubRefs(divEl, type)
7878

7979
end
8080
end
81-
pandoc.walk_block(divEl, {
81+
_quarto.ast.walk(divEl, {
8282
Div = checkForParent,
8383
Image = checkForParent
8484
})

src/resources/filters/common/tables.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ end
115115

116116
function countTables(div)
117117
local tables = 0
118-
pandoc.walk_block(div, {
118+
_quarto.ast.walk(div, {
119119
Table = function(table)
120120
tables = tables + 1
121121
end,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function filterSeq(filters)
195195
if filter.filter ~= nil then
196196
filter = filter.filter
197197
end
198-
local r = run_emulated_filter(doc, filter)
198+
local r = run_emulated_filter(doc, filter, true)
199199
if r ~= nil then
200200
doc = r
201201
result = r

src/resources/filters/crossref/format.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function refPrefix(type, upper)
6161
if upper then
6262
local el = pandoc.Plain(prefix)
6363
local firstStr = true
64-
el = pandoc.walk_block(el, {
64+
el = _quarto.ast.walk(el, {
6565
Str = function(str)
6666
if firstStr then
6767
local strText = pandoc.text.upper(pandoc.text.sub(str.text, 1, 1)) .. pandoc.text.sub(str.text, 2, -1)

src/resources/filters/crossref/preprocess.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function crossrefPreprocess()
3737
if isTableRef(el.attr.identifier) then
3838
el.attr.classes:insert("tbl-parent")
3939
end
40-
el = pandoc.walk_block(el, walkRefs(el.attr.identifier))
40+
el = _quarto.ast.walk(el, walkRefs(el.attr.identifier))
4141
end
4242
end
4343
return el
@@ -100,7 +100,7 @@ function crossrefPreprocess()
100100
el.content:insert(err)
101101
end
102102
end
103-
doc.blocks[i] = pandoc.walk_block(el, walkRefs(parentId))
103+
doc.blocks[i] = _quarto.ast.walk(el, walkRefs(parentId))
104104
end
105105
end
106106

src/resources/filters/crossref/theorems.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function crossrefPreprocessTheorems()
88
Div = function(el)
99
local type = refType(el.attr.identifier)
1010
if types[type] ~= nil or proofType(el) ~= nil then
11-
return pandoc.walk_block(el, {
11+
return _quarto.ast.walk(el, {
1212
Header = function(el)
1313
el.classes:insert("unnumbered")
1414
return el

src/resources/filters/layout/cites.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function citesPreprocess()
77

88
Note = function(note)
99
if _quarto.format.isLatexOutput() and marginCitations() then
10-
return pandoc.walk_inline(note, {
10+
return _quarto.ast.walk(note, {
1111
Inlines = walkUnresolvedCitations(function(citation, appendInline, appendAtEnd)
1212
appendAtEnd(citePlaceholderInline(citation))
1313
end)
@@ -21,7 +21,7 @@ function citesPreprocess()
2121
if hasMarginColumn(figure) or hasMarginCaption(figure) then
2222
-- This is a figure in the margin itself, we need to append citations at the end of the caption
2323
-- without any floating
24-
para.content[1] = pandoc.walk_inline(figure, {
24+
para.content[1] = _quarto.ast.walk(figure, {
2525
Inlines = walkUnresolvedCitations(function(citation, appendInline, appendAtEnd)
2626
appendAtEnd(citePlaceholderInlineWithProtection(citation))
2727
end)
@@ -30,7 +30,7 @@ function citesPreprocess()
3030
elseif marginCitations() then
3131
-- This is a figure is in the body, but the citation should be in the margin. Use
3232
-- protection to shift any citations over
33-
para.content[1] = pandoc.walk_inline(figure, {
33+
para.content[1] = _quarto.ast.walk(figure, {
3434
Inlines = walkUnresolvedCitations(function(citation, appendInline, appendAtEnd)
3535
appendInline(marginCitePlaceholderWithProtection(citation))
3636
end)
@@ -56,7 +56,7 @@ function citesPreprocess()
5656
end
5757
end
5858
else
59-
return pandoc.walk_block(div, {
59+
return _quarto.ast.walk(div, {
6060
Inlines = walkUnresolvedCitations(function(citation, appendInline, appendAtEnd)
6161
if hasMarginColumn(div) then
6262
appendAtEnd(citePlaceholderInline(citation))

src/resources/filters/layout/jats.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
function jatsDivFigure(divEl)
66

77
-- ensure that only valid elements are permitted
8-
local filteredEl = pandoc.walk_block(divEl, {
8+
local filteredEl = _quarto.ast.walk(divEl, {
99
Header = function(el)
1010
return pandoc.Strong(el.content)
1111
end

0 commit comments

Comments
 (0)