Skip to content

Commit bf889c8

Browse files
committed
recurse into custom inner content. Closes #4068.
1 parent ededbf8 commit bf889c8

File tree

3 files changed

+71
-28
lines changed

3 files changed

+71
-28
lines changed

src/resources/filters/ast/customnodes.lua

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,7 @@ function run_emulated_filter(doc, filter)
2424
end
2525

2626
function process_custom_inner(raw)
27-
if raw == nil then
28-
return nil
29-
end
30-
local custom_data, t, kind = _quarto.ast.resolve_custom_data(raw)
31-
local handler = _quarto.ast.resolve_handler(t)
32-
if handler == nil then
33-
if type(raw) == "userdata" then
34-
return raw:walk(wrapped_filter)
35-
end
36-
print(raw)
37-
error("Internal Error: handler not found for custom node " .. (t or type(t)))
38-
crash_with_stack_trace()
39-
end
40-
if handler.inner_content ~= nil then
41-
local new_inner_content = {}
42-
local inner_content = handler.inner_content(custom_data)
43-
44-
for k, v in pairs(inner_content) do
45-
local new_v = v:walk(wrapped_filter)
46-
if new_v ~= nil then
47-
new_inner_content[k] = new_v
48-
end
49-
end
50-
handler.set_inner_content(custom_data, new_inner_content)
51-
end
27+
_quarto.ast.inner_walk(raw, wrapped_filter)
5228
end
5329

5430
function process_custom_preamble(custom_data, t, kind, custom_node)
@@ -154,7 +130,9 @@ function run_emulated_filter(doc, filter)
154130
end
155131

156132
local result = doc:walk(wrapped_filter)
157-
add_trace(result, filter._filter_name)
133+
if filter._filter_name ~= nil then
134+
add_trace(result, filter._filter_name)
135+
end
158136
return result
159137
end
160138

@@ -246,6 +224,35 @@ _quarto.ast = {
246224
end
247225
return nil
248226
end,
227+
228+
inner_walk = function(raw, filter)
229+
if raw == nil then
230+
return nil
231+
end
232+
local custom_data, t, kind = _quarto.ast.resolve_custom_data(raw)
233+
local handler = _quarto.ast.resolve_handler(t)
234+
if handler == nil then
235+
if type(raw) == "userdata" then
236+
return raw:walk(filter)
237+
end
238+
print(raw)
239+
error("Internal Error: handler not found for custom node " .. (t or type(t)))
240+
crash_with_stack_trace()
241+
end
242+
243+
if handler.inner_content ~= nil then
244+
local new_inner_content = {}
245+
local inner_content = handler.inner_content(custom_data)
246+
247+
for k, v in pairs(inner_content) do
248+
local new_v = run_emulated_filter(v, filter)
249+
if new_v ~= nil then
250+
new_inner_content[k] = new_v
251+
end
252+
end
253+
handler.set_inner_content(custom_data, new_inner_content)
254+
end
255+
end,
249256
}
250257
quarto._quarto = _quarto
251258

src/resources/filters/ast/render.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ function renderExtendedNodes()
2121
return {} -- don't render in custom writers, so we can handle them in the custom writer code.
2222
end
2323

24-
return {
25-
Custom = function(node)
24+
local filter -- beware, it can't be a local initialization because of the recursive call to inner_walk
25+
filter = {
26+
Custom = function(node, raw)
2627
local handler = _quarto.ast.resolve_handler(node.t)
2728
if handler == nil then
2829
error("Internal Error: handler not found for custom node " .. node.t)
2930
crash_with_stack_trace()
3031
end
32+
_quarto.ast.inner_walk(raw, filter)
3133
return handler.render(node)
3234
end
3335
}
36+
37+
return filter
3438
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: test-4068
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- ["#subtabA-content"]
8+
---
9+
10+
::: panel-tabset
11+
### Tab A
12+
13+
ContentTabA
14+
15+
::: panel-tabset
16+
### sub-Tab A
17+
18+
[ContentSubTabA]{#subtabA-content}
19+
20+
```{r}
21+
plot(1)
22+
```
23+
24+
### sub-Tab B
25+
26+
ContentSubTabB
27+
:::
28+
29+
### Tab B
30+
31+
ContentTabB
32+
:::

0 commit comments

Comments
 (0)