fix: Add HTML entity replacements for tab and space characters by LaurentAerens · Pull Request #10 · dmsnell/diff-match-patch · GitHub
Skip to content

fix: Add HTML entity replacements for tab and space characters#10

Open
LaurentAerens wants to merge 3 commits into
dmsnell:mainfrom
LaurentAerens:fix/entity-replacements-for-tab-and-space-characters
Open

fix: Add HTML entity replacements for tab and space characters#10
LaurentAerens wants to merge 3 commits into
dmsnell:mainfrom
LaurentAerens:fix/entity-replacements-for-tab-and-space-characters

Conversation

@LaurentAerens

Copy link
Copy Markdown

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: google#144

@dmsnell

dmsnell commented Oct 14, 2025

Copy link
Copy Markdown
Owner

@LaurentAerens

Copy link
Copy Markdown
Author

I've updated it in all remaining languages.
Your idea of a different function for this sounds like a great idea and is something i will take up when i have time. maybe create an issue for it for now?

@LaurentAerens

Copy link
Copy Markdown
Author

i'm unsure about the merge conflicts, i don't see any so i'm a bit confused about what's going on.

@dmsnell

dmsnell commented Oct 15, 2025

Copy link
Copy Markdown
Owner

@LaurentAerens aha, we converted the JS library to an npm package and renamed the files. I can fix this for you if you want. otherwise the changes should apply to javascript/index.js

@LaurentAerens

Copy link
Copy Markdown
Author

@dmsnell i think i'm having an issue pulling the lastest version of main, so if you can do it for now that would be amazing. i'm going to investigate why i can't pull the lastest version.

@dmsnell

dmsnell commented Oct 15, 2025

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants