From 19ca3fe21e27c57d6c273b98177dc534ed74d2cd Mon Sep 17 00:00:00 2001 From: Rubens Andrade <38709237+andrader@users.noreply.github.com> Date: Sat, 7 Nov 2026 19:25:16 -0300 Subject: [PATCH 1/3] fix: treat emphasis and strong spans as atomic tokens in word-level diff (#60) Span boundaries come from the Typst parser (Emph/Strong nodes), so Typst's own rules apply (no emphasis inside words, none in refs, labels or raw text). When both sides keep a span with the same delimiter, the delimiters stay unmarked and the text between them is diffed recursively. --- src/diff.rs | 259 ++++++++++++++++++++++++++++++++++++++++--- tests/integration.rs | 85 ++++++++++++++ 2 files changed, 326 insertions(+), 18 deletions(-) diff --git a/src/diff.rs b/src/diff.rs index 940bc61..3880415 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -1,4 +1,5 @@ -use similar::{Algorithm, ChangeTag, DiffOp, TextDiff}; +use similar::{Algorithm, DiffOp, TextDiff}; +use typst_syntax::{SyntaxKind, SyntaxNode}; use crate::{Block, DiffResult, DiffSpan, SpanTag, TypstLabel}; @@ -137,21 +138,33 @@ fn process_replace(old_range: &[Block], new_range: &[Block], results: &mut Vec`), inline equations (`$...$`), and escape sequences -/// (`\x`) are treated as atomic tokens so the diff never fragments valid -/// Typst syntax. +/// labels (`