Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

[JavaScript] diff_prettyHtml highlight leading/trailing space difference #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions javascript/diff_match_patch_uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,11 +1254,17 @@ diff_match_patch.prototype.diff_prettyHtml = function(diffs) {
var pattern_lt = /</g;
var pattern_gt = />/g;
var pattern_para = /\n/g;
var pattern_space = /^ | $/g;

for (var x = 0; x < diffs.length; x++) {
var op = diffs[x][0]; // Operation (insert, delete, equal)
var data = diffs[x][1]; // Text of change.
var text = data.replace(pattern_amp, '&amp;').replace(pattern_lt, '&lt;')
.replace(pattern_gt, '&gt;').replace(pattern_para, '&para;<br>');
var text = data
.replace(pattern_amp, '&amp;')
.replace(pattern_lt, '&lt;')
.replace(pattern_gt, '&gt;')
.replace(pattern_para, '&para;<br>')
.replace(pattern_space, '&nbsp;');
switch (op) {
case DIFF_INSERT:
html[x] = '<ins style="background:#e6ffe6;">' + text + '</ins>';
Expand Down