A `{=html}` block holding `<style>` or `<script>` fails to parse on a page with code cells
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 65/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Rust
- Stelle
- 316
- Fork
- 23
- Merge medio
- 11h 49m
- PR unite (30g)
- 245
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di quarto-dev/q2
-
Heading anchor links have no icon: AnchorJS is initialised with an empty `icon`Forse già presa @cscheid l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
quarto-dev/q2#1419 ·
I maintainer di solito rispondono entro 1 giorno
-
bug testing windows
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
quarto-dev/q2#1346 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
quarto-dev/q2#1095 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
quarto-dev/q2#1418 ·
I maintainer di solito rispondono entro 1 giorno
-
bug readers-writers windows
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
quarto-dev/q2#1416 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di quarto-dev/q2
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
BurntSushi/jiff#755 ·
I maintainer di solito rispondono entro 1 giorno
-
After the kernel is given up on, a new import leaves "Importing…" and its Cancel on the status lineApertabug help wanted priority: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
sawhorse3d/sawhorse#163 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
MartinPTielemans/ilo#4607 ·