A `{=html}` block holding `<style>` or `<script>` fails to parse on a page with code cells

Đang mở
#1,368 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
316
Fork
23
Merge trung bình
11 giờ 49 phút
Pull request đã merge (30 ngày)
245

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của quarto-dev/q2

Tất cả issue của quarto-dev/q2

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.