Skip to content

Commit 105bd08

Browse files
committed
perf - move stripNotes to after we know if it's needed
1 parent ad03947 commit 105bd08

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

src/resources/filters/main.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ local quarto_pre_filters = {
296296
traverser = 'jog',
297297
},
298298

299+
{ name = "strip-notes-from-hidden",
300+
filter = strip_notes_from_hidden(),
301+
flags = { "has_notes" },
302+
traverser = 'jog',
303+
},
304+
299305
{ name = "pre-combined-hidden",
300306
filter = combineFilters({
301307
hidden(),

src/resources/filters/normalize/flags.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ function compute_flags()
178178
end,
179179
Figure = function(node)
180180
flags.has_pandoc3_figure = true
181-
end
181+
end,
182+
Note = function(node)
183+
flags.has_notes = true
184+
end,
182185
}, {
183186
Meta = function(el)
184187
local lightbox_auto = lightbox_module.automatic(el)

src/resources/filters/normalize/normalize.lua

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ local authors = require 'modules/authors'
2020
local license = require 'modules/license'
2121
local shortcode_ast = require 'modules/astshortcode'
2222

23-
local function stripNotes(el)
24-
local result = _quarto.ast.walk(el, {
25-
Note = function(_el)
26-
return pandoc.Null()
27-
end
28-
})
29-
return result
30-
end
31-
3223
function normalize_filter()
3324
return {
3425
Meta = function(meta)
@@ -59,22 +50,6 @@ function normalize_filter()
5950
normalized = shortcode_ast.parse(normalized)
6051

6152
return normalized
62-
end,
63-
Div = function(div)
64-
-- Don't allow footnotes in the hidden element (markdown pipeline)
65-
-- since that will result in duplicate footnotes
66-
-- in the rendered output
67-
if div.classes:includes('hidden') then
68-
return stripNotes(div)
69-
end
70-
end,
71-
Span = function(span)
72-
-- Don't allow footnotes in the hidden element (markdown pipeline)
73-
-- since that will result in duplicate footnotes
74-
-- in the rendered output
75-
if span.classes:includes('hidden') then
76-
return stripNotes(span)
77-
end
7853
end
7954
}
8055
end

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,32 @@ function hidden()
8181
end
8282
end
8383

84-
85-
86-
87-
88-
84+
function strip_notes_from_hidden()
85+
local function stripNotes(el)
86+
local result = _quarto.ast.walk(el, {
87+
Note = function(_el)
88+
return pandoc.Null()
89+
end
90+
})
91+
return result
92+
end
93+
94+
return {
95+
Div = function(div)
96+
-- Don't allow footnotes in the hidden element (markdown pipeline)
97+
-- since that will result in duplicate footnotes
98+
-- in the rendered output
99+
if div.classes:includes('hidden') then
100+
return stripNotes(div)
101+
end
102+
end,
103+
Span = function(span)
104+
-- Don't allow footnotes in the hidden element (markdown pipeline)
105+
-- since that will result in duplicate footnotes
106+
-- in the rendered output
107+
if span.classes:includes('hidden') then
108+
return stripNotes(span)
109+
end
110+
end
111+
}
112+
end

0 commit comments

Comments
 (0)