Incremental QMD writer drops bytes outside the first-to-last block range

Đang mở
#963 0 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
76/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 crates/pampa/src/writers/incremental.rs, especially assemble and emit_metadata_prefix, then trace how block offsets are obtained through SourceInfo::preimage_in. Reproduce both cases with qmd_to_pandoc, compute_reconciliation(&original, &original), and incremental_write. Done means unchanged input, including front matter and trailing blank lines, is reproduced byte for byte.

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

Mô tả

Reproduction

At tag v0.37.0 (and on main at a37801fe4), parse with pampa::wasm_entry_points::qmd_to_pandoc, compute quarto_ast_reconcile::compute_reconciliation(&original, &original) (no edit), and call pampa::writers::incremental::incremental_write.

Input A (33 bytes, front matter only, no body blocks):

---
title: Only front matter
---

Output: the empty string. The front matter is lost.

Input B (36 bytes):

First paragraph.

Last paragraph.


Output: 34 bytes; the two trailing blank lines after Last paragraph. are dropped. Editing any block in the document drops the trailing blank lines the same way — the bytes are not anchored to a block that survives editing.

Observed vs expected

Observed: with no edits, the output differs from the input — it is missing either the whole document (when it has no blocks) or the bytes after the last block (when it has one or more).

Expected: with no edits, the output equals the input exactly. Bytes before the first block (when front matter is unchanged) and bytes after the last block are copied verbatim from the original, the same way the gap between two kept blocks already is.

Cause

In crates/pampa/src/writers/incremental.rs:

  • assemble walks the coarsened block list and emits a metadata prefix, then each block with its separator, but never emits anything for the region from the end of the last block to the end of the input. There is no "epilogue" step mirroring the "prefix" step.
  • emit_metadata_prefix computes first_block_start as None when original_ast.blocks is empty, which means "no metadata prefix region" — so a document that is entirely front matter (zero body blocks) never has its front matter copied or rewritten at all.

Suggested fix

In assemble, after the main block loop, append original_qmd[last_block_end..] where last_block_end is the original AST's last block's end offset (via SourceInfo::preimage_in), when that block list is non-empty. In emit_metadata_prefix, treat a blocks-empty document's "first block start" as original_qmd.len() instead of None, so the whole document is considered the candidate metadata-prefix region instead of being skipped outright.

Ngôn ngữ chính
Rust
Star
302
Fork
22
Merge trung bình
5 giờ 2 phút
Pull request đã merge (30 ngày)
213

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.