A YAML block inside a `~~~` fenced code block is applied as document metadata
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- markdown, typescript, yaml
- Domain
- backend
Research direction
Start in src/core/yaml.ts at readYamlFromMarkdown and inspect kRegexFencedCode, also used by skipRegexpAll. Compare its handling of backtick fences with tilde fences, then find the related tests for YAML extraction. Done means YAML inside a tilde fenced code block is ignored as metadata, while the block remains code and existing backtick behavior still works.
Written by the indexing model from the issue text.
Description
Bug description
Quarto strips backtick-fenced code before looking for YAML metadata blocks in the document body, but not tilde-fenced code. A --- ... --- block inside a ~~~ fence is therefore read as front matter: its keys (lang, toc, format, execute, filters, ...) take effect. Pandoc treats the same text as a code block and ignores it, as it does for a backtick fence. The two fence styles are equivalent in CommonMark and Pandoc Markdown, so this looks like an oversight.
It matters for documents that show front matter as an example, for instance a tutorial on Quarto itself written with ~~~ fences so that it can contain a literal triple backtick. The example silently changes the real document.
Reproducible example
x.qmd (markdown engine, so no R or Python is involved):
---
title: Tilde fence
engine: markdown
---
Text before the fence.
~~~
---
lang: fr
toc: true
---
~~~
Text after the fence.
quarto render x.qmd --to html
Expected: <html lang="en">, and the fenced block shown as a code block, as with a backtick fence (the same file with ``` in place of ~~~ behaves like this).
Actual: <html ... lang="fr" xml:lang="fr">. The block is applied as metadata, and also appears as a code block in the output. A Lua filter that dumps doc.meta sees lang = fr. (quarto pandoc -f markdown -s x.qmd alone leaves lang unset, with the block as a CodeBlock.)
With a heading in the document, toc: true from inside the fence also produces a table of contents. With the knitr engine, execute: echo: false inside the fence hides all code in the document.
Cause
src/core/yaml.ts: readYamlFromMarkdown deletes fenced code with
const kRegexFencedCode = /^([\t >]*`{3,})[^`\n]*\n[\W\w]*?\n\1\s*$/gm;
(line 49 at commit 83432c0). The pattern only matches a run of backticks, so a ~~~ fence is not removed before kRegExYAML is applied. Allowing ~{3,} as well (with the closing fence being the same character, at least as long) would fix it. The same constant is used by the skipRegexpAll call at line 144.
Environment
$ quarto --version
1.11.9
$ quarto pandoc --version | head -1
pandoc 3.10
macOS; the regex is platform independent.
Related
#3004: the same kind of problem for a --- inside a backtick fence, which kRegexFencedCode addressed.
- Dominant language
- JavaScript
- Stars
- 6.2k
- Forks
- 496
- Avg merge
- 15h 47m
- Merged PRs (30d)
- 87
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quarto-dev/quarto-cli
-
accessibility bug dark-mode dashboards
Difficulty 1/5 Under an hour Newbie friendliness 84/100
quarto-dev/quarto-cli#15447 ·
Maintainers usually reply within 1 day
-
accessibility bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
quarto-dev/quarto-cli#15442 ·
Maintainers usually reply within 1 day
-
accessibility bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
quarto-dev/quarto-cli#15440 ·
Maintainers usually reply within 1 day
-
accessibility bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
quarto-dev/quarto-cli#15439 ·
Maintainers usually reply within 1 day
-
accessibility bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
quarto-dev/quarto-cli#15438 ·
Maintainers usually reply within 1 day
All issues in quarto-dev/quarto-cli
Similar issues
-
01 type: bug 41 lvl: easy
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
521xueweihan/HelloGitHub#4655 ·
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount duePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
bug CRIT-3
Difficulty 1/5 Under an hour Newbie friendliness 70/100
NASA-AMMOS/anms#426 ·