Skip to content

Commit bbef5e2

Browse files
authored
Merge pull request #10206 from quarto-dev/bugfix/10004
Lua - process shortcodes in string attributes throughout AST
2 parents 095837e + 353fe75 commit bbef5e2

File tree

16 files changed

+92
-11
lines changed

16 files changed

+92
-11
lines changed

news/changelog-1.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All changes included in 1.6:
77

88
## Lua filters
99

10+
- ([#10004](https://github.com/quarto-dev/quarto-cli/issues/10004)): Resolve callout titles, theorem names, and `code-summary` content through `quarto_ast_pipeline()` and `process_shortcodes()`.
1011
- ([#10196](https://github.com/quarto-dev/quarto-cli/issues/10196)): protect against nil values in `float.caption_long`.
1112

1213
## `typst` Format

src/resources/extensions/quarto/docusaurus/docusaurus_utils.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ function render_folded_block(block)
2626
})
2727

2828
if not isEmpty(summary) then
29-
tappend(beginPara.content, markdownToInlines(summary))
29+
local inlines = process_shortcodes(string_to_quarto_ast_inlines(summary))
30+
tappend(beginPara.content, inlines)
3031
end
3132
beginPara.content:insert(pandoc.RawInline("markdown", "</summary>"))
3233
div.content:insert(beginPara)

src/resources/filters/common/pandoc.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ function resolveHeadingCaption(div)
132132
local capEl = div.content[1]
133133
if capEl ~= nil and is_regular_node(capEl, "Header") then
134134
div.content:remove(1)
135-
return capEl.content
135+
return quarto.utils.as_inlines(capEl.content)
136136
else
137-
return nil
137+
return pandoc.Inlines({})
138138
end
139139
end
140140

src/resources/filters/crossref/theorems.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ function crossref_theorems()
5555
end
5656

5757
-- capture then remove name
58+
--
59+
-- we have string_to_quarto_ast_inlines but we don't need it here
60+
-- because this filter happened after shortcode processing, and this
61+
-- is a regular div we're processing
5862
local name = markdownToInlines(el.attr.attributes["name"])
5963
if not name or #name == 0 then
6064
name = resolveHeadingCaption(el)

src/resources/filters/customnodes/callout.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function _callout_main()
4545
-- and returns the custom node
4646
parse = function(div)
4747
quarto_global_state.hasCallouts = true
48-
local title = markdownToInlines(div.attr.attributes["title"])
48+
local title = string_to_quarto_ast_inlines(div.attr.attributes["title"] or "")
4949
if not title or #title == 0 then
5050
title = resolveHeadingCaption(div)
5151
end

src/resources/filters/customnodes/shortcodes.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ local function handle_shortcode(shortcode_tbl, node, context)
200200
return callShortcodeHandler(handler, shortcode_struct, context), shortcode_struct
201201
end
202202

203+
local _shortcodes_filter = nil
204+
function process_shortcodes(content)
205+
return _quarto.ast.walk(content, _shortcodes_filter)
206+
end
207+
203208
function shortcodes_filter()
204209

205210
local code_shortcode = shortcode_lpeg.make_shortcode_parser({
@@ -329,6 +334,8 @@ function shortcodes_filter()
329334
return doc
330335
end
331336
}
337+
338+
_shortcodes_filter = filter
332339
return filter
333340
end
334341

src/resources/filters/quarto-post/foldcode.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function render_folded_block(block)
2424
})
2525

2626
if not isEmpty(summary) then
27-
tappend(beginPara.content, markdownToInlines(summary))
27+
tappend(beginPara.content, process_shortcodes(string_to_quarto_ast_inlines(summary)))
2828
end
2929
beginPara.content:insert(pandoc.RawInline("html", "</summary>"))
3030
div.content:insert(beginPara)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function parse_blockreftargets()
1010
return
1111
end
1212
-- capture then remove name
13-
local name = markdownToInlines(el.attr.attributes["name"])
13+
local name = string_to_quarto_ast_inlines(el.attr.attributes["name"] or "")
1414
if not name or #name == 0 then
1515
name = resolveHeadingCaption(el)
1616
end
@@ -32,7 +32,7 @@ function parse_blockreftargets()
3232

3333
local name = string_to_quarto_ast_inlines(el.attributes["name"] or "")
3434
if not name or #name == 0 then
35-
name = resolveHeadingCaption(el) or pandoc.Inlines({})
35+
name = resolveHeadingCaption(el)
3636
end
3737
el.attributes["name"] = nil
3838
local identifier = el.identifier

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ local function kable_raw_latex_fixups(content, identifier)
140140
identifier = label_identifier,
141141
type = "Table",
142142
content = pandoc.Blocks({ raw }),
143-
caption_long = pandoc.Blocks({pandoc.Plain(string_to_quarto_ast_inlines(caption_content))}),
143+
caption_long = pandoc.Blocks({pandoc.Plain(string_to_quarto_ast_inlines(caption_content or ""))}),
144144
})
145145
end
146146
})

src/resources/lua-types/pandoc/inlines.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pandoc.Inlines = {}
2727
Create an inlines list
2828
]]
2929
---@param inlines any Inline elements
30-
---@return pandoc.List
30+
---@return pandoc.Inlines
3131
function pandoc.Inlines(inlines) end
3232

3333

0 commit comments

Comments
 (0)