dmsnell / diff-match-patch

Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.
Apache License 2.0
23 stars 5 forks source link

Add HTML entity replacements for tab and space characters #7

Closed LaurentAerens closed 4 months ago

LaurentAerens commented 7 months ago

diff_prettyHtml currently doesn't highlight leading/trailing space differences. Because spaces in HTML aren't visible.

This pull request changes that.

Instead of

<ins style="background:#e6ffe6;"> </ins>

diff_prettyHtml now returns

<ins style="background:#e6ffe6;">&nbsp;</ins>

resulting in differences with leading/training spaces being visible in HTML.

Example: When we compare "Test" and "Test " (notice the second string doesn't equal the first string since it has a trailing space).

var diff = dmp.diff_main("Test", "Test "); // this results in the following diff: [[0, 'Test'], [1, ' ']]

Previously looked like this:

242906142-5ebd2764-0129-49f0-b3c0-ec77319316f3

Now with this pull requests it looks like this:

242906167-f99add6a-79c2-42f5-8286-fa043903b9f5

Note: this issue also seems to be present in the JavaScript implementation: https://github.com/google/diff-match-patch/pull/144

LaurentAerens commented 5 months ago

Is there any potential this PR could get a review?