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

未關閉 適合新手
#15,431 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
84/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
markdown, typescript, yaml
領域
backend

研究方向

從 src/core/yaml.ts 中的 readYamlFromMarkdown 開始,檢查 skipRegexpAll 也會使用的 kRegexFencedCode。比較它對反引號圍欄程式碼區塊和波浪號圍欄程式碼區塊的處理方式,接著找出與 YAML 擷取相關的測試。完成條件是:波浪號圍欄程式碼區塊中的 YAML 會被忽略,不作為中繼資料;該區塊仍是程式碼;現有的反引號處理行為也能繼續正常運作。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
JavaScript
星號
6.2k
分支
492
平均合併
13 小時 51 分鐘
30 天內合併 PR
82

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

quarto-dev/quarto-cli 的其他 Issue

查看 quarto-dev/quarto-cli 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。