Incremental QMD writer drops bytes outside the first-to-last block range
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 76/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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:
assemblewalks 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_prefixcomputesfirst_block_startasNonewhenoriginal_ast.blocksis 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.
- Dominant language
- Rust
- Stars
- 302
- Forks
- 22
- Avg merge
- 5h 2m
- Merged PRs (30d)
- 213
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quarto-dev/q2
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
quarto-dev/q2#1219 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
quarto-dev/q2#1188 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
quarto-dev/q2#1179 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
quarto-dev/q2#1133 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
quarto-dev/q2#1103 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
storytold/photocraft#15350 ·
Maintainers usually reply within 1 day
-
area:davinci
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ubugeeei-prod/vize#13167 ·
Maintainers usually reply within 1 day
-
area:ui enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
transit-audio/transit#738 ·
Maintainers usually reply within 1 day
-
enhancement good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
hocinehacherouf/liberarr#78 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day