CRLF source puts raw carriage returns inside rendered code blocks (HTML and docx)
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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- html, rust
- Lĩnh vực
- backend, documentation
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- 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
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của quarto-dev/q2
-
Heading anchor links have no icon: AnchorJS is initialised with an empty `icon`Có thể đã có người làm @cscheid đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
quarto-dev/q2#1419 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug testing windows
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
quarto-dev/q2#1346 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
quarto-dev/q2#1095 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 67/100
quarto-dev/q2#1418 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Most knitr engines are not yet supported: {cat}, {css}, {Rcpp}... cells go to JupyterCó thể đã có người làm @cderv đã nhận 3 ngày trước. Đang mởfeature-port
quarto-dev/q2#1413 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của quarto-dev/q2
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
BurntSushi/jiff#755 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
After the kernel is given up on, a new import leaves "Importing…" and its Cancel on the status lineĐang mởbug help wanted priority: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
sawhorse3d/sawhorse#163 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
MartinPTielemans/ilo#4607 ·