From 137c881455ef76afac200506be3c1cd29211eaa5 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Sun, 7 Sep 2025 14:18:08 -0500 Subject: [PATCH] shortcodes - ensure contents works in metadata (#13342) --- news/changelog-1.9.md | 5 +++++ .../filters/quarto-pre/contentsshortcode.lua | 10 ++++----- .../docs/smoke-all/2025/09/07/issue-13342.qmd | 22 +++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 news/changelog-1.9.md create mode 100644 tests/docs/smoke-all/2025/09/07/issue-13342.qmd diff --git a/news/changelog-1.9.md b/news/changelog-1.9.md new file mode 100644 index 00000000000..84c6a94179e --- /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 174d9ddfc69..8499ce06279 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 00000000000..9275c027c88 --- /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}