You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Word-level diff splits emphasis and strong delimiters across marks, producing unclosed delimiters #60
When an emphasis (_..._) or strong (*...*) span of several words is added, deleted or reworded, the word-level diff splits it across several #diff-*[...] calls. The opening and closing delimiters end up in different content blocks, so the output does not compile (unclosed delimiter).
Checked on main at d7d062b (after #26). Emphasis that is kept while the words inside it change already works there (A _quick brown_ fox. → A _slow brown_ fox. gives A _#diff-deleted[quick]#diff-added[slow] brown_ fox.), so this is the case where the delimiters themselves are added, removed or moved.
A #diff-deleted[_quick]#diff-added[slow] #diff-deleted[brown_]#diff-added[red] fox.
typst compile fails with:
error: unclosed delimiter
Other cases with the same cause
old
new
output (preamble omitted)
A quick brown fox.
A _slow red_ fox.
A #diff-deleted[quick]#diff-added[_slow] #diff-deleted[brown]#diff-added[red_] fox.
A *quick brown* fox.
A quick *brown* fox.
A #diff-deleted[*]quick #diff-added[*]brown* fox.
Use the _adapted Ribeiro algorithm_ here.
Use the adaptation of the SQV algorithm here.
Use the #diff-deleted[_adapted]#diff-added[adaptation of the] #diff-deleted[Ribeiro]#diff-added[SQV] algorithm#diff-deleted[_] here.
All of them fail with unclosed delimiter.
Context
I found this diffing a thesis written in Typst. With main, 10 of the 32 changed chapter files of a large revision still produce Typst that does not compile, and the ones I traced fail like this: a rewritten sentence that used to contain an _emphasised phrase_ or started with a *Bold run-in heading.*.
Possible fix
Something like #26 did for inline equations: when an Emph or Strong node is not identical in old and new, treat the whole node (delimiters included) as one atomic token, so a changed span is deleted and re-added as a unit (#diff-deleted[_quick brown_]#diff-added[slow red]). Another option is to diff inside the node only when both sides have it, and otherwise keep the delimiters together with their content in one mark.
Activity
fix: keep intraword _ and * inside the word token in word-level diff (s…