A YAML block inside a `~~~` fenced code block is applied as document metadata

Aperta Adatta ai principianti
#15,431 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
markdown, typescript, yaml
Ambito
backend

Direzione di ricerca

Inizia da src/core/yaml.ts, in readYamlFromMarkdown, ed esamina kRegexFencedCode, usato anche da skipRegexpAll. Confronta la gestione dei blocchi di codice delimitati da backtick con quella dei blocchi delimitati da tilde, poi trova i test correlati all’estrazione dello YAML. Il lavoro è completo quando lo YAML all’interno di un blocco di codice delimitato da tilde viene ignorato come metadato, il blocco rimane codice e il comportamento esistente con i blocchi delimitati da backtick continua a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
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.

Lingua principale
JavaScript
Stelle
6.2k
Fork
492
Merge medio
13h 51m
PR unite (30g)
82

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di quarto-dev/quarto-cli

Tutte le issue di quarto-dev/quarto-cli

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.