Fix: Ensure equalities processed via new processEqualities hook (Fixes #219) #224
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new extension point,
processEqualities(), insideDiffRowGeneratorto address the HTML-escaping issue described in #219.Previously, equal (unchanged) segments were passed through HTML normalization only once.
Because
<and>were normalized to&lt;and&gt;, equalities that began with&caused incorrect inline diff grouping (e.g.,&lt;vs&gt;). This produced invalid HTML wheninlineDiffByWord(true)was used.What This PR Changes
✔ Adds a new protected hook:
✔ All equality chunks now pass through this hook before becoming
DiffRow(Tag.EQUAL, ...).✔ Default behavior is no modification (fully backward compatible).
✔ Users can override this hook to customize HTML or text transformations after diffing, solving the core issue.
Why this Fix Works
The problem in #219 occurs because the diff logic compares normalized text, but the final output does not normalize equal segments the same way as diffs.
By exposing
processEqualities(), we give users a consistent post-diff transformation path.This ensures that equal text is handled symmetrically to diffed text and prevents HTML-breaking cases like
&lt;/&gt;being partially diffed.Backward Compatibility
Tests Included
✔ Added
DiffRowGeneratorEqualitiesTest✔ Verifies that:
processEqualities()Fixes
Fixes #219