Skip to content

Commit 137c881

Browse files
committed
shortcodes - ensure contents works in metadata (#13342)
1 parent 10af0a2 commit 137c881

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

news/changelog-1.9.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
All changes included in 1.9:
2+
3+
## Shortcodes
4+
5+
- ([#13342](https://github.com/quarto-dev/quarto-cli/issues/13342)): Ensure that the `contents` shortcode works inside metadata.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function contents_shortcode_filter()
2929

3030
return {
3131
Pandoc = function(doc)
32-
_quarto.ast.walk(doc.blocks, {
32+
doc = doc:walk({
3333
RawInline = function(el)
3434
if el.format ~= "quarto-internal" then
3535
return
@@ -44,7 +44,8 @@ function contents_shortcode_filter()
4444
end
4545
end
4646
})
47-
doc.blocks = _quarto.ast.walk(doc.blocks, {
47+
48+
doc = doc:walk({
4849
Div = function(el)
4950
if ids_used[el.attr.identifier] then
5051
divs[el.attr.identifier] = el
@@ -110,13 +111,12 @@ function contents_shortcode_filter()
110111
"Removing from document.")
111112
return {}
112113
end
113-
-- replace div-context entries
114-
doc.blocks = _quarto.ast.walk(doc.blocks, {
114+
doc = doc:walk({
115115
Para = handle_block,
116116
Plain = handle_block
117117
})
118118
-- replace span-context entries
119-
doc.blocks = _quarto.ast.walk(doc.blocks, {
119+
doc = doc:walk({
120120
RawInline = function(el)
121121
if el.format ~= "quarto-internal" then
122122
return
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: "I wish I could write inline code in the abstract"
3+
author: carlos
4+
format: latex
5+
abstract: |
6+
This is an abstract. My fancy value is {{< contents placeholder-source >}}.
7+
_quarto:
8+
tests:
9+
latex:
10+
ensureFileRegexMatches:
11+
- ['\{7\}\.\n\\end\{abstract\}']
12+
- []
13+
---
14+
15+
## A section
16+
17+
```{r}
18+
#| include: false
19+
my_fancy_code <- 3 + 4
20+
```
21+
22+
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}

0 commit comments

Comments
 (0)