CRLF source puts raw carriage returns inside rendered code blocks (HTML and docx)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- html, rust
- Ambito
- backend, documentation
Direzione di ricerca
Start with the linked code_fence_content.rs and fenced_code_block.rs locations to trace how fenced code preserves CRLF bytes, then follow the HTML writer and the JSON sent to Pandoc for docx. Compare CRLF and LF fixtures while keeping source offsets and qmd round-tripping intact. Done means rendered HTML and docx contain no stray carriage returns in code, with existing CRLF source behavior preserved.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
A .qmd file with CRLF line endings, which is what a Windows checkout with core.autocrlf gives, renders its fenced code blocks with raw \r bytes inside the code. I believe this is because the reader keeps the CRLF of the code body as written in the AST, and the writers then copy that text through while they write every structural newline as LF. The HTML ends up with mixed line endings and a lone \r before </code>, and docx gets a \r at the end of each code line inside <w:t>. Pandoc on the same file produces no \r at all.
Reproduction
I can reproduce with the 0.48.0-nightly.20261128 nightly on Windows. The file is created with printf so the CRLF bytes don't depend on the checkout or the editor:
printf -- '---\r\ntitle: crlf\r\n---\r\n\r\n```\r\nx = 1\r\ny = 2\r\n```\r\n' > crlf.qmd
q2 render crlf.qmd
tr -cd '\r' < crlf.html | wc -c
#> 2
q2 render crlf.qmd --to docx
unzip -p crlf.docx word/document.xml | tr -cd '\r' | wc -c
#> 2
The code block in crlf.html, as bytes (od -c), is <pre><code>x = 1\r\ny = 2\r</code></pre>\n, while the rest of the page uses \n only. In word/document.xml the runs are <w:t xml:space="preserve">x = 1\r</w:t> and <w:t xml:space="preserve">y = 2\r</w:t>. With syntax highlighting (a python fence), the \r lands in its own run at the end of each line. The same file with LF endings gives 0 in both counts.
For comparison, pandoc 3.14 normalizes the line endings when it reads the file:
pandoc -f markdown -t native crlf.qmd
#> [ CodeBlock ( "" , [] , [] ) "x = 1\ny = 2" ]
pandoc -f markdown -t html --eol=lf crlf.qmd -o pandoc.html
tr -cd '\r' < pandoc.html | wc -c
#> 0
pandoc -f markdown -t docx crlf.qmd -o pandoc.docx
unzip -p pandoc.docx word/document.xml | tr -cd '\r' | wc -c
#> 0
Where the \r comes from
The \r is already in the AST: pampa -t native crlf.qmd prints CodeBlock ( "" , [] , [] ) "x = 1\ny = 2" with a raw \r byte after 1 and after 2 (the native writer doesn't escape it either). The body of a fenced block is built by copying the input byte range, and blank lines inside a list item are re-added "as written, \n or \r\n":
Then the trailing newline strip pops only the final \n, which leaves the lone \r before </code>:
From there, the HTML writer escapes only & < > " ' in the code text, and docx goes through pandoc via JSON, which writes the \r into the run text. I think this is also what was behind the mermaid docx parity failure in quarto-dev/q2#1347, which quarto-dev/q2#1392 fixed by pinning the fixture to LF, so the product behaviour stayed as it was.
Other constructs I checked with the same CRLF-vs-LF comparison in HTML: raw blocks ({=html}) and display math ($$) keep the \r the same way, and so does a fence inside a list item. Paragraph soft breaks, multi-line inline code, blockquotes, a YAML block scalar (abstract: |) and inline math come out without \r. An executed {python} cell (Jupyter) also comes out clean.
What a fix needs to keep
Keeping the CRLF as written looks deliberate: source locations are byte offsets into the original file, and the qmd writer, including the incremental writer from quarto-dev/q2#966, needs to round-trip a CRLF document byte for byte. So normalizing the input before parsing is not an option. We could instead:
- normalize
\r\nto\nat the rendered-output boundaries only (the HTML writer's text output, and the JSON handed to pandoc for docx and the other pandoc-based formats), leaving the AST and the qmd writer as they are; - or have the writers emit the input's convention everywhere, so a CRLF source gives uniform CRLF HTML. This would not help docx, where a
\rinside<w:t>is never right.
Either way the lone trailing \r from the newline strip should go. I don't know yet which of the two the team prefers for HTML, since pandoc's default --eol=native gives uniform CRLF HTML on Windows (2 \r for this file, one per output line).
- 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
-
Most knitr engines are not yet supported: {cat}, {css}, {Rcpp}... cells go to JupyterForse già presa @cderv l’ha presa 3 giorni fa. Apertafeature-port
quarto-dev/q2#1413 · 1 commento · 1 assegnatario ·
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 ·