A `{=html}` block holding `<style>` or `<script>` fails to parse on a page with code cells
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with round_trips_bare_html and write_rawblock in crates/pampa/src/writers/qmd.rs, then read the related tests for raw HTML round trips. Check how fenced {=html} blocks containing style and script elements are serialized and parsed when a document has a code cell. Done when both reproductions render successfully and preserve the raw HTML in the output.
由索引模型根据 Issue 内容生成。
描述
This issue was written by Claude while adding q2 support to
Great Docs. The output shown comes from running each repro.
Bug description
A ```{=html} block that holds a <style> or <script> element renders correctly on a page
without code cells. On a page with a code cell, the same block fails with a parse error in the
intermediate .jupyter.rmarkdown file, at the block's CSS or JavaScript.
Before running an engine, serialize_ast_to_qmd in
crates/quarto-core/src/stage/stages/engine_execution.rs writes the document as qmd, and the qmd
writer drops the block's fence. write_rawblock in crates/pampa/src/writers/qmd.rs writes HTML
bare when round_trips_bare_html accepts it, and that function accepts any raw-text element
(<pre>, <script>, <style>, <textarea>) on its opening tag alone. Its doc comment says the
reader leaves such an element's interior unparsed. But the interior is parsed as Markdown before
paragraph.rs lifts the paragraph to a RawBlock, so braces and indented lines are errors when
the intermediate file is read.
#674 reported this along with bare <style> and <script> elements, and was closed as not
planned: q2 will discourage bare elements because their contents can't be parsed reliably. This
issue is only about the fenced form, which is what an author is asked to write instead, and which
q2's own writer turns into the bare form. Keeping the fence on raw-text elements in
round_trips_bare_html, as #674 suggested, would fix it.
Great Docs wrote a <style> rule on its homepage this way, and pages with code cells failed to
render under q2. It now puts the rule in its stylesheet instead, so this no longer blocks Great
Docs.
Steps to reproduce
With Python and ipykernel available:
mkdir raw-style && cd raw-style
printf -- '---\ntitle: Raw style\n---\n\n```{=html}\n<style>\nh1 { color: red; }\n</style>\n```\n' > plain.qmd
printf -- '---\ntitle: Raw style\n---\n\n```{=html}\n<style>\nh1 { color: red; }\n</style>\n```\n\n```{python}\n1 + 1\n```\n' > code.qmd
q2 render plain.qmd
q2 render code.qmd
Actual behavior
plain.qmd renders, and plain.html has the <style> element. code.qmd fails:
error: while rendering /private/tmp/raw-style/code.qmd
Error: [Q-2-41] Curly braces are reserved for attribute syntax
╭─[ /private/tmp/raw-style/code.jupyter.rmarkdown:136:5 ]
│
136 │ h1 { color: red; }
│ ───┬───
│ ╰───── Curly braces are reserved for attribute syntax in Quarto markdown. To write literal braces, escape them as `\{...\}`. If you meant to attach an attribute, use `.class` / `#id` / `key="value"` syntax, e.g. `[text]{.class}`.
─────╯
error: while rendering /private/tmp/raw-style/code.qmd
Error: Parse error
╭─[ /private/tmp/raw-style/code.jupyter.rmarkdown:153:4 ]
│
153 │ :::
│ ┬
│ ╰── unexpected character or token here
─────╯
2 errors
A <script> block holding if (a) { and an indented b(); line fails the same way, with a parse
error at the indented line. The same block wrapped in <div> instead of <style> keeps its fence
and renders.
Expected behavior
code.qmd renders as plain.qmd does, with the <style> element in the output, as in Quarto
1.9.37.
- 主要语言
- Rust
- 星标
- 316
- 派生
- 23
- 平均合并
- 11 小时 49 分钟
- 30 天内合并 PR
- 245
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
quarto-dev/q2 的其他 Issue
-
Heading anchor links have no icon: AnchorJS is initialised with an empty `icon`可能已有人在做 @cscheid 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
quarto-dev/q2#1419 ·
维护者通常 1 天内回复
-
bug testing windows
难度 1/5 1-3 小时 新手友好度 78/100
quarto-dev/q2#1346 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
quarto-dev/q2#1095 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 67/100
quarto-dev/q2#1418 ·
维护者通常 1 天内回复
-
bug readers-writers windows
难度 4/5 3-5 天 新手友好度 48/100
quarto-dev/q2#1416 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 82/100
BurntSushi/jiff#755 ·
维护者通常 1 天内回复
-
After the kernel is given up on, a new import leaves "Importing…" and its Cancel on the status line未关闭bug help wanted priority: low
难度 2/5 1-3 小时 新手友好度 78/100
sawhorse3d/sawhorse#163 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
MartinPTielemans/ilo#4607 ·