Fix Typst label handling in diff output#8
Conversation
Treat Typst labels as atomic syntax during tokenization and avoid word-level diffing label-only blocks. Keep labels at paragraph starts as separate blocks so unchanged labels remain attached to nearby content, and render inserted labels bare while suppressing deleted label spans. Add regressions for renamed labels and unchanged labels near inserted text.
There was a problem hiding this comment.
Pull request overview
This PR improves Typst label handling in typdiff output so generated diffs remain valid Typst and label-based references continue to resolve. It does so by recognizing <label> syntax as atomic during inline diffing, splitting paragraph-start labels into their own blocks, and rendering labels without wrapping them in diff markup.
Changes:
- Parse labels at paragraph start as their own paragraph blocks and treat label-only blocks as atomic (skip word-diffing inside them).
- Tokenize
<label>as a single token during mixed-granularity word diffing to prevent diff markup from splitting label syntax. - Render inserted labels bare and suppress deleted label output; add regression tests covering renamed and unchanged labels near edits.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/lib.rs |
Introduces TypstLabel helper and marks label-only paragraph blocks as atomic. |
src/diff.rs |
Updates mixed tokenizer to treat <label> as an atomic token (via TypstLabel). |
src/parse.rs |
Splits paragraph-start labels into their own paragraph blocks; adds parser regression test. |
src/render.rs |
Renders labels bare (and suppresses deleted label output) to avoid invalid/duplicate labels; adds renderer regression test. |
tests/integration.rs |
Adds integration tests for renamed labels and unchanged label placement relative to added content. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| SpanTag::Deleted => { | ||
| if is_label_only(&span.text) { | ||
| prev_was_diff = false; |
|
Thanks for the review, fixed. I updated Added regression coverage for both fixes, including the following cases:
|
Summary
Fix Typst label handling in generated diff output.
This change treats Typst labels like
<sample-anchor>as atomic syntax duringinline diffing. It prevents diff markup from being inserted inside label syntax,
and keeps unchanged labels outside added/deleted wrappers so references can
continue to resolve.
Closes #7.
Changes
<label>syntax as a single token during mixed-granularity diffing.or duplicate labels.
content.