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

Offen Anfängerfreundlich
#15,431 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
84/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
markdown, typescript, yaml
Bereich
backend

Rechercherichtung

Beginne in src/core/yaml.ts bei readYamlFromMarkdown und untersuche kRegexFencedCode, das auch von skipRegexpAll verwendet wird. Vergleiche den Umgang mit Backtick-Codeblöcken mit dem von Tilde-Codeblöcken und suche anschließend die zugehörigen Tests zur YAML-Extraktion. Fertig ist die Änderung, wenn YAML innerhalb eines Tilde-Codeblocks als Metadaten ignoriert wird, der Block aber weiterhin Code bleibt und das bisherige Verhalten bei Backtick-Codeblöcken weiterhin funktioniert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
JavaScript
Sterne
6.2k
Forks
492
Ø Merge
13 Std. 51 Min.
Gemergte PRs (30 T.)
82

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus quarto-dev/quarto-cli

Alle Issues in quarto-dev/quarto-cli

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.