diff --git a/news/changelog-1.9.md b/news/changelog-1.9.md new file mode 100644 index 0000000000..84c6a94179 --- /dev/null +++ b/news/changelog-1.9.md @@ -0,0 +1,5 @@ +All changes included in 1.9: + +## Shortcodes + +- ([#13342](https://github.com/quarto-dev/quarto-cli/issues/13342)): Ensure that the `contents` shortcode works inside metadata. diff --git a/src/resources/filters/quarto-pre/contentsshortcode.lua b/src/resources/filters/quarto-pre/contentsshortcode.lua index 174d9ddfc6..8499ce0627 100644 --- a/src/resources/filters/quarto-pre/contentsshortcode.lua +++ b/src/resources/filters/quarto-pre/contentsshortcode.lua @@ -29,7 +29,7 @@ function contents_shortcode_filter() return { Pandoc = function(doc) - _quarto.ast.walk(doc.blocks, { + doc = doc:walk({ RawInline = function(el) if el.format ~= "quarto-internal" then return @@ -44,7 +44,8 @@ function contents_shortcode_filter() end end }) - doc.blocks = _quarto.ast.walk(doc.blocks, { + + doc = doc:walk({ Div = function(el) if ids_used[el.attr.identifier] then divs[el.attr.identifier] = el @@ -110,13 +111,12 @@ function contents_shortcode_filter() "Removing from document.") return {} end - -- replace div-context entries - doc.blocks = _quarto.ast.walk(doc.blocks, { + doc = doc:walk({ Para = handle_block, Plain = handle_block }) -- replace span-context entries - doc.blocks = _quarto.ast.walk(doc.blocks, { + doc = doc:walk({ RawInline = function(el) if el.format ~= "quarto-internal" then return diff --git a/tests/docs/smoke-all/2025/09/07/issue-13342.qmd b/tests/docs/smoke-all/2025/09/07/issue-13342.qmd new file mode 100644 index 0000000000..9275c027c8 --- /dev/null +++ b/tests/docs/smoke-all/2025/09/07/issue-13342.qmd @@ -0,0 +1,22 @@ +--- +title: "I wish I could write inline code in the abstract" +author: carlos +format: latex +abstract: | + This is an abstract. My fancy value is {{< contents placeholder-source >}}. +_quarto: + tests: + latex: + ensureFileRegexMatches: + - ['\{7\}\.\n\\end\{abstract\}'] + - [] +--- + +## A section + +```{r} +#| include: false +my_fancy_code <- 3 + 4 +``` + +Of course when I do it here it works. We analyze `{r} my_fancy_code` articles and find that this doesn't work at all. [`{r} my_fancy_code`]{#placeholder-source}