diff --git a/cpp/diff_match_patch.cpp b/cpp/diff_match_patch.cpp index 64f270c3..a6914e41 100644 --- a/cpp/diff_match_patch.cpp +++ b/cpp/diff_match_patch.cpp @@ -1276,7 +1276,8 @@ QString diff_match_patch::diff_prettyHtml(const QList &diffs) { foreach(Diff aDiff, diffs) { text = aDiff.text; text.replace("&", "&").replace("<", "<") - .replace(">", ">").replace("\n", "¶
"); + .replace(">", ">").replace("\n", "¶
") + .replace("\t", " ").replace(" ", " "); switch (aDiff.operation) { case INSERT: html += QString("") + text diff --git a/csharp/DiffMatchPatch.cs b/csharp/DiffMatchPatch.cs index 6e196418..67247b31 100644 --- a/csharp/DiffMatchPatch.cs +++ b/csharp/DiffMatchPatch.cs @@ -1338,7 +1338,7 @@ public string diff_prettyHtml(List diffs) { StringBuilder html = new StringBuilder(); foreach (Diff aDiff in diffs) { string text = aDiff.text.Replace("&", "&").Replace("<", "<") - .Replace(">", ">").Replace("\n", "¶
"); + .Replace(">", ">").Replace("\n", "¶
").Replace("\t", " ").Replace(" ", " ");; switch (aDiff.operation) { case Operation.INSERT: html.Append("").Append(text) diff --git a/dart/DMPClass.dart b/dart/DMPClass.dart index 7be14226..d278c611 100644 --- a/dart/DMPClass.dart +++ b/dart/DMPClass.dart @@ -1256,7 +1256,9 @@ class DiffMatchPatch { .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') - .replaceAll('\n', '¶
'); + .replaceAll('\n', '¶
') + .replaceAll('\t', ' ') + .replaceAll(' ', ' '); switch (aDiff.operation) { case Operation.insert: html.write(''); diff --git a/java/src/name/fraser/neil/plaintext/diff_match_patch.java b/java/src/name/fraser/neil/plaintext/diff_match_patch.java index d467f7fa..5de03e92 100644 --- a/java/src/name/fraser/neil/plaintext/diff_match_patch.java +++ b/java/src/name/fraser/neil/plaintext/diff_match_patch.java @@ -1382,7 +1382,8 @@ public String diff_prettyHtml(List diffs) { StringBuilder html = new StringBuilder(); for (Diff aDiff : diffs) { String text = aDiff.text.replace("&", "&").replace("<", "<") - .replace(">", ">").replace("\n", "¶
"); + .replace(">", ">").replace("\n", "¶
") + .replace("\t", " ").replace(" ", " "); switch (aDiff.operation) { case INSERT: html.append("").append(text) diff --git a/javascript/diff_match_patch.js b/javascript/diff_match_patch.js index 56b12cd8..1a732a6c 100644 --- a/javascript/diff_match_patch.js +++ b/javascript/diff_match_patch.js @@ -30,7 +30,7 @@ diff_match_patch.prototype.digit16=function(a){switch(a){case "0":return 0;case diff_match_patch.prototype.decodeURI=function(a){try{return decodeURI(a)}catch(h){for(var b=0,d="";b=c)){d+=String.fromCharCode((c&65535)>>>10&1023|55296);d+=String.fromCharCode(56320|c&1023); b+=12;continue}throw new URIError("URI malformed");}}}}return d}};diff_match_patch.prototype.diff_xIndex=function(a,b){var d=0,c=0,e=0,f=0,g;for(g=0;gb)break;e=d;f=c}return a.length!=g&&a[g][0]===DIFF_DELETE?f:f+(b-e)}; -diff_match_patch.prototype.diff_prettyHtml=function(a){a=this.diff_cleanupSplitSurrogates(a);for(var b=[],d=/&/g,c=//g,f=/\n/g,g=0;g");switch(h){case DIFF_INSERT:b[g]=''+l+"";break;case DIFF_DELETE:b[g]=''+l+"";break;case DIFF_EQUAL:b[g]=""+l+""}}return b.join("")}; +diff_match_patch.prototype.diff_prettyHtml=function(a){a=this.diff_cleanupSplitSurrogates(a);for(var b=[],d=/&/g,c=//g,f=/\n/g,g=/\t/g,h=/ /g,l=0;l").replace(g," ").replace(h," ");switch(m){case DIFF_INSERT:b[l]=''+n+"";break;case DIFF_DELETE:b[l]=''+n+"";break;case DIFF_EQUAL:b[l]=""+n+""}}return b.join("")}; diff_match_patch.prototype.diff_text1=function(a){for(var b=[],d=0;d} Array of diff tuples. */ -diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines, - opt_deadline) { +diff_match_patch.prototype.diff_main = function (text1, text2, opt_checklines, + opt_deadline) { // Set a deadline by which time the diff must be complete. if (typeof opt_deadline == 'undefined') { if (this.Diff_Timeout <= 0) { @@ -171,8 +171,8 @@ diff_match_patch.prototype.diff_main = function(text1, text2, opt_checklines, * @return {!Array.} Array of diff tuples. * @private */ -diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, - deadline) { +diff_match_patch.prototype.diff_compute_ = function (text1, text2, checklines, + deadline) { var diffs; if (!text1) { @@ -191,9 +191,9 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, if (i != -1) { // Shorter text is inside the longer text (speedup). diffs = [new diff_match_patch.Diff(DIFF_INSERT, longtext.substring(0, i)), - new diff_match_patch.Diff(DIFF_EQUAL, shorttext), - new diff_match_patch.Diff(DIFF_INSERT, - longtext.substring(i + shorttext.length))]; + new diff_match_patch.Diff(DIFF_EQUAL, shorttext), + new diff_match_patch.Diff(DIFF_INSERT, + longtext.substring(i + shorttext.length))]; // Swap insertions for deletions if diff is reversed. if (text1.length > text2.length) { diffs[0][0] = diffs[2][0] = DIFF_DELETE; @@ -205,7 +205,7 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, // Single character string. // After the previous speedup, the character can't be an equality. return [new diff_match_patch.Diff(DIFF_DELETE, text1), - new diff_match_patch.Diff(DIFF_INSERT, text2)]; + new diff_match_patch.Diff(DIFF_INSERT, text2)]; } // Check to see if the problem can be split in two. @@ -222,7 +222,7 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, var diffs_b = this.diff_main(text1_b, text2_b, checklines, deadline); // Merge the results. return diffs_a.concat([new diff_match_patch.Diff(DIFF_EQUAL, mid_common)], - diffs_b); + diffs_b); } if (checklines && text1.length > 100 && text2.length > 100) { @@ -243,7 +243,7 @@ diff_match_patch.prototype.diff_compute_ = function(text1, text2, checklines, * @return {!Array.} Array of diff tuples. * @private */ -diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) { +diff_match_patch.prototype.diff_lineMode_ = function (text1, text2, deadline) { // Scan the text on a line-by-line basis first. var a = this.diff_linesToChars_(text1, text2); text1 = a.chars1; @@ -280,10 +280,10 @@ diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) { if (count_delete >= 1 && count_insert >= 1) { // Delete the offending records and add the merged ones. diffs.splice(pointer - count_delete - count_insert, - count_delete + count_insert); + count_delete + count_insert); pointer = pointer - count_delete - count_insert; var subDiff = - this.diff_main(text_delete, text_insert, false, deadline); + this.diff_main(text_delete, text_insert, false, deadline); for (var j = subDiff.length - 1; j >= 0; j--) { diffs.splice(pointer, 0, subDiff[j]); } @@ -313,7 +313,7 @@ diff_match_patch.prototype.diff_lineMode_ = function(text1, text2, deadline) { * @return {!Array.} Array of diff tuples. * @private */ -diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { +diff_match_patch.prototype.diff_bisect_ = function (text1, text2, deadline) { // Cache the text lengths to prevent multiple calls. var text1_length = text1.length; var text2_length = text2.length; @@ -357,7 +357,7 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { } var y1 = x1 - k1; while (x1 < text1_length && y1 < text2_length && - text1.charAt(x1) == text2.charAt(y1)) { + text1.charAt(x1) == text2.charAt(y1)) { x1++; y1++; } @@ -392,8 +392,8 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { } var y2 = x2 - k2; while (x2 < text1_length && y2 < text2_length && - text1.charAt(text1_length - x2 - 1) == - text2.charAt(text2_length - y2 - 1)) { + text1.charAt(text1_length - x2 - 1) == + text2.charAt(text2_length - y2 - 1)) { x2++; y2++; } @@ -422,7 +422,7 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { // Diff took too long and hit the deadline or // number of diffs equals number of characters, no commonality at all. return [new diff_match_patch.Diff(DIFF_DELETE, text1), - new diff_match_patch.Diff(DIFF_INSERT, text2)]; + new diff_match_patch.Diff(DIFF_INSERT, text2)]; }; @@ -437,8 +437,8 @@ diff_match_patch.prototype.diff_bisect_ = function(text1, text2, deadline) { * @return {!Array.} Array of diff tuples. * @private */ -diff_match_patch.prototype.diff_bisectSplit_ = function(text1, text2, x, y, - deadline) { +diff_match_patch.prototype.diff_bisectSplit_ = function (text1, text2, x, y, + deadline) { var text1a = text1.substring(0, x); var text2a = text2.substring(0, y); var text1b = text1.substring(x); @@ -463,7 +463,7 @@ diff_match_patch.prototype.diff_bisectSplit_ = function(text1, text2, x, y, * The zeroth element of the array of unique strings is intentionally blank. * @private */ -diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) { +diff_match_patch.prototype.diff_linesToChars_ = function (text1, text2) { var lineArray = []; // e.g. lineArray[4] == 'Hello\n' var lineHash = {}; // e.g. lineHash['Hello\n'] == 4 @@ -496,7 +496,7 @@ diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) { var line = text.substring(lineStart, lineEnd + 1); if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) : - (lineHash[line] !== undefined)) { + (lineHash[line] !== undefined)) { chars += String.fromCharCode(lineHash[line]); } else { if (lineArrayLength == maxLines) { @@ -518,7 +518,7 @@ diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) { var chars1 = diff_linesToCharsMunge_(text1); maxLines = 65535; var chars2 = diff_linesToCharsMunge_(text2); - return {chars1: chars1, chars2: chars2, lineArray: lineArray}; + return { chars1: chars1, chars2: chars2, lineArray: lineArray }; }; @@ -529,7 +529,7 @@ diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) { * @param {!Array.} lineArray Array of unique strings. * @private */ -diff_match_patch.prototype.diff_charsToLines_ = function(diffs, lineArray) { +diff_match_patch.prototype.diff_charsToLines_ = function (diffs, lineArray) { for (var i = 0; i < diffs.length; i++) { var chars = diffs[i][1]; var text = []; @@ -548,7 +548,7 @@ diff_match_patch.prototype.diff_charsToLines_ = function(diffs, lineArray) { * @return {number} The number of characters common to the start of each * string. */ -diff_match_patch.prototype.diff_commonPrefix = function(text1, text2) { +diff_match_patch.prototype.diff_commonPrefix = function (text1, text2) { // Quick check for common null cases. if (!text1 || !text2 || text1.charAt(0) != text2.charAt(0)) { return 0; @@ -561,7 +561,7 @@ diff_match_patch.prototype.diff_commonPrefix = function(text1, text2) { var pointerstart = 0; while (pointermin < pointermid) { if (text1.substring(pointerstart, pointermid) == - text2.substring(pointerstart, pointermid)) { + text2.substring(pointerstart, pointermid)) { pointermin = pointermid; pointerstart = pointermin; } else { @@ -579,10 +579,10 @@ diff_match_patch.prototype.diff_commonPrefix = function(text1, text2) { * @param {string} text2 Second string. * @return {number} The number of characters common to the end of each string. */ -diff_match_patch.prototype.diff_commonSuffix = function(text1, text2) { +diff_match_patch.prototype.diff_commonSuffix = function (text1, text2) { // Quick check for common null cases. if (!text1 || !text2 || - text1.charAt(text1.length - 1) != text2.charAt(text2.length - 1)) { + text1.charAt(text1.length - 1) != text2.charAt(text2.length - 1)) { return 0; } // Binary search. @@ -593,7 +593,7 @@ diff_match_patch.prototype.diff_commonSuffix = function(text1, text2) { var pointerend = 0; while (pointermin < pointermid) { if (text1.substring(text1.length - pointermid, text1.length - pointerend) == - text2.substring(text2.length - pointermid, text2.length - pointerend)) { + text2.substring(text2.length - pointermid, text2.length - pointerend)) { pointermin = pointermid; pointerend = pointermin; } else { @@ -613,7 +613,7 @@ diff_match_patch.prototype.diff_commonSuffix = function(text1, text2) { * string and the start of the second string. * @private */ -diff_match_patch.prototype.diff_commonOverlap_ = function(text1, text2) { +diff_match_patch.prototype.diff_commonOverlap_ = function (text1, text2) { // Cache the text lengths to prevent multiple calls. var text1_length = text1.length; var text2_length = text2.length; @@ -646,7 +646,7 @@ diff_match_patch.prototype.diff_commonOverlap_ = function(text1, text2) { } length += found; if (found == 0 || text1.substring(text_length - length) == - text2.substring(0, length)) { + text2.substring(0, length)) { best = length; length++; } @@ -665,7 +665,7 @@ diff_match_patch.prototype.diff_commonOverlap_ = function(text1, text2) { * text2 and the common middle. Or null if there was no match. * @private */ -diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) { +diff_match_patch.prototype.diff_halfMatch_ = function (text1, text2) { if (this.Diff_Timeout <= 0) { // Don't risk returning a non-optimal diff if we have unlimited time. return null; @@ -697,12 +697,12 @@ diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) { var best_longtext_a, best_longtext_b, best_shorttext_a, best_shorttext_b; while ((j = shorttext.indexOf(seed, j + 1)) != -1) { var prefixLength = dmp.diff_commonPrefix(longtext.substring(i), - shorttext.substring(j)); + shorttext.substring(j)); var suffixLength = dmp.diff_commonSuffix(longtext.substring(0, i), - shorttext.substring(0, j)); + shorttext.substring(0, j)); if (best_common.length < suffixLength + prefixLength) { best_common = shorttext.substring(j - suffixLength, j) + - shorttext.substring(j, j + prefixLength); + shorttext.substring(j, j + prefixLength); best_longtext_a = longtext.substring(0, i - suffixLength); best_longtext_b = longtext.substring(i + prefixLength); best_shorttext_a = shorttext.substring(0, j - suffixLength); @@ -711,7 +711,7 @@ diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) { } if (best_common.length * 2 >= longtext.length) { return [best_longtext_a, best_longtext_b, - best_shorttext_a, best_shorttext_b, best_common]; + best_shorttext_a, best_shorttext_b, best_common]; } else { return null; } @@ -719,10 +719,10 @@ diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) { // First check if the second quarter is the seed for a half-match. var hm1 = diff_halfMatchI_(longtext, shorttext, - Math.ceil(longtext.length / 4)); + Math.ceil(longtext.length / 4)); // Check again based on the third quarter. var hm2 = diff_halfMatchI_(longtext, shorttext, - Math.ceil(longtext.length / 2)); + Math.ceil(longtext.length / 2)); var hm; if (!hm1 && !hm2) { return null; @@ -757,7 +757,7 @@ diff_match_patch.prototype.diff_halfMatch_ = function(text1, text2) { * Reduce the number of edits by eliminating semantically trivial equalities. * @param {!Array.} diffs Array of diff tuples. */ -diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { +diff_match_patch.prototype.diff_cleanupSemantic = function (diffs) { var changes = false; var equalities = []; // Stack of indices where equalities are found. var equalitiesLength = 0; // Keeping our own length var is faster in JS. @@ -788,12 +788,12 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { // Eliminate an equality that is smaller or equal to the edits on both // sides of it. if (lastEquality && (lastEquality.length <= - Math.max(length_insertions1, length_deletions1)) && - (lastEquality.length <= Math.max(length_insertions2, - length_deletions2))) { + Math.max(length_insertions1, length_deletions1)) && + (lastEquality.length <= Math.max(length_insertions2, + length_deletions2))) { // Duplicate record. diffs.splice(equalities[equalitiesLength - 1], 0, - new diff_match_patch.Diff(DIFF_DELETE, lastEquality)); + new diff_match_patch.Diff(DIFF_DELETE, lastEquality)); // Change second copy to insert. diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; // Throw away the equality we just deleted. @@ -827,35 +827,35 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { pointer = 1; while (pointer < diffs.length) { if (diffs[pointer - 1][0] == DIFF_DELETE && - diffs[pointer][0] == DIFF_INSERT) { + diffs[pointer][0] == DIFF_INSERT) { var deletion = diffs[pointer - 1][1]; var insertion = diffs[pointer][1]; var overlap_length1 = this.diff_commonOverlap_(deletion, insertion); var overlap_length2 = this.diff_commonOverlap_(insertion, deletion); if (overlap_length1 >= overlap_length2) { if (overlap_length1 >= deletion.length / 2 || - overlap_length1 >= insertion.length / 2) { + overlap_length1 >= insertion.length / 2) { // Overlap found. Insert an equality and trim the surrounding edits. diffs.splice(pointer, 0, new diff_match_patch.Diff(DIFF_EQUAL, - insertion.substring(0, overlap_length1))); + insertion.substring(0, overlap_length1))); diffs[pointer - 1][1] = - deletion.substring(0, deletion.length - overlap_length1); + deletion.substring(0, deletion.length - overlap_length1); diffs[pointer + 1][1] = insertion.substring(overlap_length1); pointer++; } } else { if (overlap_length2 >= deletion.length / 2 || - overlap_length2 >= insertion.length / 2) { + overlap_length2 >= insertion.length / 2) { // Reverse overlap found. // Insert an equality and swap and trim the surrounding edits. diffs.splice(pointer, 0, new diff_match_patch.Diff(DIFF_EQUAL, - deletion.substring(0, overlap_length2))); + deletion.substring(0, overlap_length2))); diffs[pointer - 1][0] = DIFF_INSERT; diffs[pointer - 1][1] = - insertion.substring(0, insertion.length - overlap_length2); + insertion.substring(0, insertion.length - overlap_length2); diffs[pointer + 1][0] = DIFF_DELETE; diffs[pointer + 1][1] = - deletion.substring(overlap_length2); + deletion.substring(overlap_length2); pointer++; } } @@ -872,7 +872,7 @@ diff_match_patch.prototype.diff_cleanupSemantic = function(diffs) { * e.g: The cat came. -> The cat came. * @param {!Array.} diffs Array of diff tuples. */ -diff_match_patch.prototype.diff_cleanupSemanticLossless = function(diffs) { +diff_match_patch.prototype.diff_cleanupSemanticLossless = function (diffs) { /** * Given two strings, compute a score representing whether the internal * boundary falls on logical boundaries. @@ -899,17 +899,17 @@ diff_match_patch.prototype.diff_cleanupSemanticLossless = function(diffs) { var nonAlphaNumeric1 = char1.match(diff_match_patch.nonAlphaNumericRegex_); var nonAlphaNumeric2 = char2.match(diff_match_patch.nonAlphaNumericRegex_); var whitespace1 = nonAlphaNumeric1 && - char1.match(diff_match_patch.whitespaceRegex_); + char1.match(diff_match_patch.whitespaceRegex_); var whitespace2 = nonAlphaNumeric2 && - char2.match(diff_match_patch.whitespaceRegex_); + char2.match(diff_match_patch.whitespaceRegex_); var lineBreak1 = whitespace1 && - char1.match(diff_match_patch.linebreakRegex_); + char1.match(diff_match_patch.linebreakRegex_); var lineBreak2 = whitespace2 && - char2.match(diff_match_patch.linebreakRegex_); + char2.match(diff_match_patch.linebreakRegex_); var blankLine1 = lineBreak1 && - one.match(diff_match_patch.blanklineEndRegex_); + one.match(diff_match_patch.blanklineEndRegex_); var blankLine2 = lineBreak2 && - two.match(diff_match_patch.blanklineStartRegex_); + two.match(diff_match_patch.blanklineStartRegex_); if (blankLine1 || blankLine2) { // Five points for blank lines. @@ -934,7 +934,7 @@ diff_match_patch.prototype.diff_cleanupSemanticLossless = function(diffs) { // Intentionally ignore the first and last element (don't need checking). while (pointer < diffs.length - 1) { if (diffs[pointer - 1][0] == DIFF_EQUAL && - diffs[pointer + 1][0] == DIFF_EQUAL) { + diffs[pointer + 1][0] == DIFF_EQUAL) { // This is a single edit surrounded by equalities. var equality1 = diffs[pointer - 1][1]; var edit = diffs[pointer][1]; @@ -954,13 +954,13 @@ diff_match_patch.prototype.diff_cleanupSemanticLossless = function(diffs) { var bestEdit = edit; var bestEquality2 = equality2; var bestScore = diff_cleanupSemanticScore_(equality1, edit) + - diff_cleanupSemanticScore_(edit, equality2); + diff_cleanupSemanticScore_(edit, equality2); while (edit.charAt(0) === equality2.charAt(0)) { equality1 += edit.charAt(0); edit = edit.substring(1) + equality2.charAt(0); equality2 = equality2.substring(1); var score = diff_cleanupSemanticScore_(equality1, edit) + - diff_cleanupSemanticScore_(edit, equality2); + diff_cleanupSemanticScore_(edit, equality2); // The >= encourages trailing rather than leading whitespace on edits. if (score >= bestScore) { bestScore = score; @@ -1002,7 +1002,7 @@ diff_match_patch.blanklineStartRegex_ = /^\r?\n\r?\n/; * Reduce the number of edits by eliminating operationally trivial equalities. * @param {!Array.} diffs Array of diff tuples. */ -diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { +diff_match_patch.prototype.diff_cleanupEfficiency = function (diffs) { var changes = false; var equalities = []; // Stack of indices where equalities are found. var equalitiesLength = 0; // Keeping our own length var is faster in JS. @@ -1021,7 +1021,7 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { while (pointer < diffs.length) { if (diffs[pointer][0] == DIFF_EQUAL) { // Equality found. if (diffs[pointer][1].length < this.Diff_EditCost && - (post_ins || post_del)) { + (post_ins || post_del)) { // Candidate found. equalities[equalitiesLength++] = pointer; pre_ins = post_ins; @@ -1048,11 +1048,11 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { * ABXC */ if (lastEquality && ((pre_ins && pre_del && post_ins && post_del) || - ((lastEquality.length < this.Diff_EditCost / 2) && - (pre_ins + pre_del + post_ins + post_del) == 3))) { + ((lastEquality.length < this.Diff_EditCost / 2) && + (pre_ins + pre_del + post_ins + post_del) == 3))) { // Duplicate record. diffs.splice(equalities[equalitiesLength - 1], 0, - new diff_match_patch.Diff(DIFF_DELETE, lastEquality)); + new diff_match_patch.Diff(DIFF_DELETE, lastEquality)); // Change second copy to insert. diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; equalitiesLength--; // Throw away the equality we just deleted; @@ -1064,7 +1064,7 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { } else { equalitiesLength--; // Throw away the previous equality. pointer = equalitiesLength > 0 ? - equalities[equalitiesLength - 1] : -1; + equalities[equalitiesLength - 1] : -1; post_ins = post_del = false; } changes = true; @@ -1084,7 +1084,7 @@ diff_match_patch.prototype.diff_cleanupEfficiency = function(diffs) { * Any edit section can move as long as it doesn't cross an equality. * @param {!Array.} diffs Array of diff tuples. */ -diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { +diff_match_patch.prototype.diff_cleanupMerge = function (diffs) { // Add a dummy entry at the end. diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, '')); var pointer = 0; @@ -1113,13 +1113,13 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { commonlength = this.diff_commonPrefix(text_insert, text_delete); if (commonlength !== 0) { if ((pointer - count_delete - count_insert) > 0 && - diffs[pointer - count_delete - count_insert - 1][0] == - DIFF_EQUAL) { + diffs[pointer - count_delete - count_insert - 1][0] == + DIFF_EQUAL) { diffs[pointer - count_delete - count_insert - 1][1] += - text_insert.substring(0, commonlength); + text_insert.substring(0, commonlength); } else { diffs.splice(0, 0, new diff_match_patch.Diff(DIFF_EQUAL, - text_insert.substring(0, commonlength))); + text_insert.substring(0, commonlength))); pointer++; } text_insert = text_insert.substring(commonlength); @@ -1129,11 +1129,11 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { commonlength = this.diff_commonSuffix(text_insert, text_delete); if (commonlength !== 0) { diffs[pointer][1] = text_insert.substring(text_insert.length - - commonlength) + diffs[pointer][1]; + commonlength) + diffs[pointer][1]; text_insert = text_insert.substring(0, text_insert.length - - commonlength); + commonlength); text_delete = text_delete.substring(0, text_delete.length - - commonlength); + commonlength); } } // Delete the offending records and add the merged ones. @@ -1141,12 +1141,12 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { diffs.splice(pointer, count_delete + count_insert); if (text_delete.length) { diffs.splice(pointer, 0, - new diff_match_patch.Diff(DIFF_DELETE, text_delete)); + new diff_match_patch.Diff(DIFF_DELETE, text_delete)); pointer++; } if (text_insert.length) { diffs.splice(pointer, 0, - new diff_match_patch.Diff(DIFF_INSERT, text_insert)); + new diff_match_patch.Diff(DIFF_INSERT, text_insert)); pointer++; } pointer++; @@ -1176,24 +1176,24 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { // Intentionally ignore the first and last element (don't need checking). while (pointer < diffs.length - 1) { if (diffs[pointer - 1][0] == DIFF_EQUAL && - diffs[pointer + 1][0] == DIFF_EQUAL) { + diffs[pointer + 1][0] == DIFF_EQUAL) { // This is a single edit surrounded by equalities. if (diffs[pointer][1].substring(diffs[pointer][1].length - - diffs[pointer - 1][1].length) == diffs[pointer - 1][1]) { + diffs[pointer - 1][1].length) == diffs[pointer - 1][1]) { // Shift the edit over the previous equality. diffs[pointer][1] = diffs[pointer - 1][1] + - diffs[pointer][1].substring(0, diffs[pointer][1].length - - diffs[pointer - 1][1].length); + diffs[pointer][1].substring(0, diffs[pointer][1].length - + diffs[pointer - 1][1].length); diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1]; diffs.splice(pointer - 1, 1); changes = true; } else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) == - diffs[pointer + 1][1]) { + diffs[pointer + 1][1]) { // Shift the edit over the next equality. diffs[pointer - 1][1] += diffs[pointer + 1][1]; diffs[pointer][1] = - diffs[pointer][1].substring(diffs[pointer + 1][1].length) + - diffs[pointer + 1][1]; + diffs[pointer][1].substring(diffs[pointer + 1][1].length) + + diffs[pointer + 1][1]; diffs.splice(pointer + 1, 1); changes = true; } @@ -1211,12 +1211,12 @@ diff_match_patch.prototype.diff_cleanupMerge = function(diffs) { * * @param {!Array.} diffs Array of diff tuples. */ -diff_match_patch.prototype.diff_cleanupSplitSurrogates = function(diffs) { +diff_match_patch.prototype.diff_cleanupSplitSurrogates = function (diffs) { var lastEnd; for (var x = 0; x < diffs.length; x++) { var thisDiff = diffs[x]; - var thisTop = thisDiff[1][0]; - var thisEnd = thisDiff[1][thisDiff[1].length - 1]; + var thisTop = thisDiff[1][0]; + var thisEnd = thisDiff[1][thisDiff[1].length - 1]; if (0 === thisDiff[1].length) { diffs.splice(x--, 1); @@ -1241,17 +1241,17 @@ diff_match_patch.prototype.diff_cleanupSplitSurrogates = function(diffs) { return diffs; }; -diff_match_patch.prototype.isHighSurrogate = function(c) { +diff_match_patch.prototype.isHighSurrogate = function (c) { var v = c.charCodeAt(0); return v >= 0xD800 && v <= 0xDBFF; }; -diff_match_patch.prototype.isLowSurrogate = function(c) { +diff_match_patch.prototype.isLowSurrogate = function (c) { var v = c.charCodeAt(0); return v >= 0xDC00 && v <= 0xDFFF; }; -diff_match_patch.prototype.digit16 = function(c) { +diff_match_patch.prototype.digit16 = function (c) { switch (c) { case '0': return 0; case '1': return 1; @@ -1289,15 +1289,15 @@ diff_match_patch.prototype.digit16 = function(c) { * @param {String} text input string encoded by encodeURI() or equivalent * @return {String} */ -diff_match_patch.prototype.decodeURI = function(text) { +diff_match_patch.prototype.decodeURI = function (text) { try { return decodeURI(text); - } catch ( e ) { + } catch (e) { var i = 0; var decoded = ''; while (i < text.length) { - if ( text[i] !== '%' ) { + if (text[i] !== '%') { decoded += text[i++]; continue; } @@ -1375,7 +1375,7 @@ diff_match_patch.prototype.decodeURI = function(text) { * @param {number} loc Location within text1. * @return {number} Location within text2. */ -diff_match_patch.prototype.diff_xIndex = function(diffs, loc) { +diff_match_patch.prototype.diff_xIndex = function (diffs, loc) { var chars1 = 0; var chars2 = 0; var last_chars1 = 0; @@ -1408,18 +1408,26 @@ diff_match_patch.prototype.diff_xIndex = function(diffs, loc) { * @param {!Array.} diffs Array of diff tuples. * @return {string} HTML representation. */ -diff_match_patch.prototype.diff_prettyHtml = function(diffs) { +diff_match_patch.prototype.diff_prettyHtml = function (diffs) { diffs = this.diff_cleanupSplitSurrogates(diffs); var html = []; var pattern_amp = /&/g; var pattern_lt = //g; var pattern_para = /\n/g; + var pattern_tab = /\t/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, '&').replace(pattern_lt, '<') - .replace(pattern_gt, '>').replace(pattern_para, '¶
'); + var text = data + .replace(pattern_amp, '&') + .replace(pattern_lt, '<') + .replace(pattern_gt, '>') + .replace(pattern_para, '¶
') + .replace(pattern_tab, ' ') + .replace(pattern_space, ' '); switch (op) { case DIFF_INSERT: html[x] = '' + text + ''; @@ -1441,7 +1449,7 @@ diff_match_patch.prototype.diff_prettyHtml = function(diffs) { * @param {!Array.} diffs Array of diff tuples. * @return {string} Source text. */ -diff_match_patch.prototype.diff_text1 = function(diffs) { +diff_match_patch.prototype.diff_text1 = function (diffs) { var text = []; for (var x = 0; x < diffs.length; x++) { if (diffs[x][0] !== DIFF_INSERT) { @@ -1457,7 +1465,7 @@ diff_match_patch.prototype.diff_text1 = function(diffs) { * @param {!Array.} diffs Array of diff tuples. * @return {string} Destination text. */ -diff_match_patch.prototype.diff_text2 = function(diffs) { +diff_match_patch.prototype.diff_text2 = function (diffs) { var text = []; for (var x = 0; x < diffs.length; x++) { if (diffs[x][0] !== DIFF_DELETE) { @@ -1474,7 +1482,7 @@ diff_match_patch.prototype.diff_text2 = function(diffs) { * @param {!Array.} diffs Array of diff tuples. * @return {number} Number of changes. */ -diff_match_patch.prototype.diff_levenshtein = function(diffs) { +diff_match_patch.prototype.diff_levenshtein = function (diffs) { var levenshtein = 0; var insertions = 0; var deletions = 0; @@ -1509,7 +1517,7 @@ diff_match_patch.prototype.diff_levenshtein = function(diffs) { * @param {!Array.} diffs Array of diff tuples. * @return {string} Delta text. */ -diff_match_patch.prototype.diff_toDelta = function(diffs) { +diff_match_patch.prototype.diff_toDelta = function (diffs) { diffs = this.diff_cleanupSplitSurrogates(diffs); var text = []; for (var x = 0; x < diffs.length; x++) { @@ -1537,7 +1545,7 @@ diff_match_patch.prototype.diff_toDelta = function(diffs) { * @return {!Array.} Array of diff tuples. * @throws {!Error} If invalid input. */ -diff_match_patch.prototype.diff_fromDelta = function(text1, delta) { +diff_match_patch.prototype.diff_fromDelta = function (text1, delta) { var diffs = []; var diffsLength = 0; // Keeping our own length var is faster in JS. var pointer = 0; // Cursor in text1 @@ -1550,14 +1558,14 @@ diff_match_patch.prototype.diff_fromDelta = function(text1, delta) { case '+': try { diffs[diffsLength++] = - new diff_match_patch.Diff(DIFF_INSERT, this.decodeURI(param)); + new diff_match_patch.Diff(DIFF_INSERT, this.decodeURI(param)); } catch (ex) { // Malformed URI sequence. throw new Error('Illegal escape in diff_fromDelta: ' + param); } break; case '-': - // Fall through. + // Fall through. case '=': var n = parseInt(param, 10); if (isNaN(n) || n < 0) { @@ -1575,13 +1583,13 @@ diff_match_patch.prototype.diff_fromDelta = function(text1, delta) { // Anything else is an error. if (tokens[x]) { throw new Error('Invalid diff operation in diff_fromDelta: ' + - tokens[x]); + tokens[x]); } } } if (pointer != text1.length) { throw new Error('Delta length (' + pointer + - ') does not equal source text length (' + text1.length + ').'); + ') does not equal source text length (' + text1.length + ').'); } return diffs; }; @@ -1597,7 +1605,7 @@ diff_match_patch.prototype.diff_fromDelta = function(text1, delta) { * @param {number} loc The location to search around. * @return {number} Best match index or -1. */ -diff_match_patch.prototype.match_main = function(text, pattern, loc) { +diff_match_patch.prototype.match_main = function (text, pattern, loc) { // Check for null inputs. if (text == null || pattern == null || loc == null) { throw new Error('Null input. (match_main)'); @@ -1629,7 +1637,7 @@ diff_match_patch.prototype.match_main = function(text, pattern, loc) { * @return {number} Best match index or -1. * @private */ -diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) { +diff_match_patch.prototype.match_bitap_ = function (text, pattern, loc) { if (pattern.length > this.Match_MaxBits) { throw new Error('Pattern too long for this browser.'); } @@ -1667,7 +1675,7 @@ diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) { best_loc = text.lastIndexOf(pattern, loc + pattern.length); if (best_loc != -1) { score_threshold = - Math.min(match_bitapScore_(0, best_loc), score_threshold); + Math.min(match_bitapScore_(0, best_loc), score_threshold); } } @@ -1707,8 +1715,8 @@ diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) { rd[j] = ((rd[j + 1] << 1) | 1) & charMatch; } else { // Subsequent passes: fuzzy match. rd[j] = (((rd[j + 1] << 1) | 1) & charMatch) | - (((last_rd[j + 1] | last_rd[j]) << 1) | 1) | - last_rd[j + 1]; + (((last_rd[j + 1] | last_rd[j]) << 1) | 1) | + last_rd[j + 1]; } if (rd[j] & matchmask) { var score = match_bitapScore_(d, j - 1); @@ -1744,7 +1752,7 @@ diff_match_patch.prototype.match_bitap_ = function(text, pattern, loc) { * @return {!Object} Hash of character locations. * @private */ -diff_match_patch.prototype.match_alphabet_ = function(pattern) { +diff_match_patch.prototype.match_alphabet_ = function (pattern) { var s = {}; for (var i = 0; i < pattern.length; i++) { s[pattern.charAt(i)] = 0; @@ -1766,7 +1774,7 @@ diff_match_patch.prototype.match_alphabet_ = function(pattern) { * @param {string} text Source text. * @private */ -diff_match_patch.prototype.patch_addContext_ = function(patch, text) { +diff_match_patch.prototype.patch_addContext_ = function (patch, text) { if (text.length == 0) { return; } @@ -1779,11 +1787,11 @@ diff_match_patch.prototype.patch_addContext_ = function(patch, text) { // Look for the first and last matches of pattern in text. If two different // matches are found, increase the pattern length. while (text.indexOf(pattern) != text.lastIndexOf(pattern) && - pattern.length < this.Match_MaxBits - this.Patch_Margin - - this.Patch_Margin) { + pattern.length < this.Match_MaxBits - this.Patch_Margin - + this.Patch_Margin) { padding += this.Patch_Margin; pattern = text.substring(patch.start2 - padding, - patch.start2 + patch.length1 + padding); + patch.start2 + patch.length1 + padding); } // Add one chunk for good luck. padding += this.Patch_Margin; @@ -1807,7 +1815,7 @@ diff_match_patch.prototype.patch_addContext_ = function(patch, text) { padding++; } var suffix = text.substring(patch.start2 + patch.length1, - patch.start2 + patch.length1 + padding); + patch.start2 + patch.length1 + padding); if (suffix) { patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, suffix)); } @@ -1843,10 +1851,10 @@ diff_match_patch.prototype.patch_addContext_ = function(patch, text) { * for text1 to text2 (method 4) or undefined (methods 1,2,3). * @return {!Array.} Array of Patch objects. */ -diff_match_patch.prototype.patch_make = function(a, opt_b, opt_c) { +diff_match_patch.prototype.patch_make = function (a, opt_b, opt_c) { var text1, diffs; if (typeof a == 'string' && typeof opt_b == 'string' && - typeof opt_c == 'undefined') { + typeof opt_c == 'undefined') { // Method 1: text1, text2 // Compute diffs from text1 and text2. text1 = /** @type {string} */(a); @@ -1856,18 +1864,18 @@ diff_match_patch.prototype.patch_make = function(a, opt_b, opt_c) { this.diff_cleanupEfficiency(diffs); } } else if (a && typeof a == 'object' && typeof opt_b == 'undefined' && - typeof opt_c == 'undefined') { + typeof opt_c == 'undefined') { // Method 2: diffs // Compute text1 from diffs. diffs = /** @type {!Array.} */(a); text1 = this.diff_text1(diffs); } else if (typeof a == 'string' && opt_b && typeof opt_b == 'object' && - typeof opt_c == 'undefined') { + typeof opt_c == 'undefined') { // Method 3: text1, diffs text1 = /** @type {string} */(a); diffs = /** @type {!Array.} */(opt_b); } else if (typeof a == 'string' && typeof opt_b == 'string' && - opt_c && typeof opt_c == 'object') { + opt_c && typeof opt_c == 'object') { // Method 4: text1, text2, diffs // text2 is not used. text1 = /** @type {string} */(a); @@ -1905,18 +1913,18 @@ diff_match_patch.prototype.patch_make = function(a, opt_b, opt_c) { patch.diffs[patchDiffLength++] = diffs[x]; patch.length2 += diff_text.length; postpatch_text = postpatch_text.substring(0, char_count2) + diff_text + - postpatch_text.substring(char_count2); + postpatch_text.substring(char_count2); break; case DIFF_DELETE: patch.length1 += diff_text.length; patch.diffs[patchDiffLength++] = diffs[x]; postpatch_text = postpatch_text.substring(0, char_count2) + - postpatch_text.substring(char_count2 + - diff_text.length); + postpatch_text.substring(char_count2 + + diff_text.length); break; case DIFF_EQUAL: if (diff_text.length <= 2 * this.Patch_Margin && - patchDiffLength && diffs.length != x + 1) { + patchDiffLength && diffs.length != x + 1) { // Small equality inside a patch. patch.diffs[patchDiffLength++] = diffs[x]; patch.length1 += diff_text.length; @@ -1962,7 +1970,7 @@ diff_match_patch.prototype.patch_make = function(a, opt_b, opt_c) { * @param {!Array.} patches Array of Patch objects. * @return {!Array.} Array of Patch objects. */ -diff_match_patch.prototype.patch_deepCopy = function(patches) { +diff_match_patch.prototype.patch_deepCopy = function (patches) { // Making deep copies is hard in JavaScript. var patchesCopy = []; for (var x = 0; x < patches.length; x++) { @@ -1971,7 +1979,7 @@ diff_match_patch.prototype.patch_deepCopy = function(patches) { patchCopy.diffs = []; for (var y = 0; y < patch.diffs.length; y++) { patchCopy.diffs[y] = - new diff_match_patch.Diff(patch.diffs[y][0], patch.diffs[y][1]); + new diff_match_patch.Diff(patch.diffs[y][0], patch.diffs[y][1]); } patchCopy.start1 = patch.start1; patchCopy.start2 = patch.start2; @@ -1991,7 +1999,7 @@ diff_match_patch.prototype.patch_deepCopy = function(patches) { * @return {!Array.>} Two element Array, containing the * new text and an array of boolean values. */ -diff_match_patch.prototype.patch_apply = function(patches, text) { +diff_match_patch.prototype.patch_apply = function (patches, text) { if (patches.length == 0) { return [text, []]; } @@ -2018,11 +2026,11 @@ diff_match_patch.prototype.patch_apply = function(patches, text) { // patch_splitMax will only provide an oversized pattern in the case of // a monster delete. start_loc = this.match_main(text, text1.substring(0, this.Match_MaxBits), - expected_loc); + expected_loc); if (start_loc != -1) { end_loc = this.match_main(text, - text1.substring(text1.length - this.Match_MaxBits), - expected_loc + text1.length - this.Match_MaxBits); + text1.substring(text1.length - this.Match_MaxBits), + expected_loc + text1.length - this.Match_MaxBits); if (end_loc == -1 || start_loc >= end_loc) { // Can't find valid trailing context. Drop this patch. start_loc = -1; @@ -2049,15 +2057,15 @@ diff_match_patch.prototype.patch_apply = function(patches, text) { if (text1 == text2) { // Perfect match, just shove the replacement text in. text = text.substring(0, start_loc) + - this.diff_text2(patches[x].diffs) + - text.substring(start_loc + text1.length); + this.diff_text2(patches[x].diffs) + + text.substring(start_loc + text1.length); } else { // Imperfect match. Run a diff to get a framework of equivalent // indices. var diffs = this.diff_main(text1, text2, false); if (text1.length > this.Match_MaxBits && - this.diff_levenshtein(diffs) / text1.length > - this.Patch_DeleteThreshold) { + this.diff_levenshtein(diffs) / text1.length > + this.Patch_DeleteThreshold) { // The end points match, but the content is unacceptably bad. results[x] = false; } else { @@ -2071,11 +2079,11 @@ diff_match_patch.prototype.patch_apply = function(patches, text) { } if (mod[0] === DIFF_INSERT) { // Insertion text = text.substring(0, start_loc + index2) + mod[1] + - text.substring(start_loc + index2); + text.substring(start_loc + index2); } else if (mod[0] === DIFF_DELETE) { // Deletion text = text.substring(0, start_loc + index2) + - text.substring(start_loc + this.diff_xIndex(diffs, - index1 + mod[1].length)); + text.substring(start_loc + this.diff_xIndex(diffs, + index1 + mod[1].length)); } if (mod[0] !== DIFF_DELETE) { index1 += mod[1].length; @@ -2097,7 +2105,7 @@ diff_match_patch.prototype.patch_apply = function(patches, text) { * @param {!Array.} patches Array of Patch objects. * @return {string} The padding string added to each side. */ -diff_match_patch.prototype.patch_addPadding = function(patches) { +diff_match_patch.prototype.patch_addPadding = function (patches) { var paddingLength = this.Patch_Margin; var nullPadding = ''; for (var x = 1; x <= paddingLength; x++) { @@ -2156,7 +2164,7 @@ diff_match_patch.prototype.patch_addPadding = function(patches) { * Intended to be called only from within patch_apply. * @param {!Array.} patches Array of Patch objects. */ -diff_match_patch.prototype.patch_splitMax = function(patches) { +diff_match_patch.prototype.patch_splitMax = function (patches) { var patch_size = this.Match_MaxBits; for (var x = 0; x < patches.length; x++) { if (patches[x].length1 <= patch_size) { @@ -2179,7 +2187,7 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, precontext)); } while (bigpatch.diffs.length !== 0 && - patch.length1 < patch_size - this.Patch_Margin) { + patch.length1 < patch_size - this.Patch_Margin) { var diff_type = bigpatch.diffs[0][0]; var diff_text = bigpatch.diffs[0][1]; if (diff_type === DIFF_INSERT) { @@ -2189,8 +2197,8 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { patch.diffs.push(bigpatch.diffs.shift()); empty = false; } else if (diff_type === DIFF_DELETE && patch.diffs.length == 1 && - patch.diffs[0][0] == DIFF_EQUAL && - diff_text.length > 2 * patch_size) { + patch.diffs[0][0] == DIFF_EQUAL && + diff_text.length > 2 * patch_size) { // This is a large deletion. Let it pass in one chunk. patch.length1 += diff_text.length; start1 += diff_text.length; @@ -2200,7 +2208,7 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { } else { // Deletion or equality. Only take as much as we can stomach. diff_text = diff_text.substring(0, - patch_size - patch.length1 - this.Patch_Margin); + patch_size - patch.length1 - this.Patch_Margin); patch.length1 += diff_text.length; start1 += diff_text.length; if (diff_type === DIFF_EQUAL) { @@ -2214,22 +2222,22 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { bigpatch.diffs.shift(); } else { bigpatch.diffs[0][1] = - bigpatch.diffs[0][1].substring(diff_text.length); + bigpatch.diffs[0][1].substring(diff_text.length); } } } // Compute the head context for the next patch. precontext = this.diff_text2(patch.diffs); precontext = - precontext.substring(precontext.length - this.Patch_Margin); + precontext.substring(precontext.length - this.Patch_Margin); // Append the end context for this patch. var postcontext = this.diff_text1(bigpatch.diffs) - .substring(0, this.Patch_Margin); + .substring(0, this.Patch_Margin); if (postcontext !== '') { patch.length1 += postcontext.length; patch.length2 += postcontext.length; if (patch.diffs.length !== 0 && - patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL) { + patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL) { patch.diffs[patch.diffs.length - 1][1] += postcontext; } else { patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, postcontext)); @@ -2248,7 +2256,7 @@ diff_match_patch.prototype.patch_splitMax = function(patches) { * @param {!Array.} patches Array of Patch objects. * @return {string} Text representation of patches. */ -diff_match_patch.prototype.patch_toText = function(patches) { +diff_match_patch.prototype.patch_toText = function (patches) { var text = []; for (var x = 0; x < patches.length; x++) { text[x] = patches[x]; @@ -2263,7 +2271,7 @@ diff_match_patch.prototype.patch_toText = function(patches) { * @return {!Array.} Array of Patch objects. * @throws {!Error} If invalid input. */ -diff_match_patch.prototype.patch_fromText = function(textline) { +diff_match_patch.prototype.patch_fromText = function (textline) { var patches = []; if (!textline) { return patches; @@ -2338,7 +2346,7 @@ diff_match_patch.prototype.patch_fromText = function(textline) { * Class representing one patch operation. * @constructor */ -diff_match_patch.patch_obj = function() { +diff_match_patch.patch_obj = function () { /** @type {!Array.} */ this.diffs = []; /** @type {?number} */ @@ -2358,7 +2366,7 @@ diff_match_patch.patch_obj = function() { * Indices are printed as 1-based, not 0-based. * @return {string} The GNU diff string. */ -diff_match_patch.patch_obj.prototype.toString = function() { +diff_match_patch.patch_obj.prototype.toString = function () { var coords1, coords2; if (this.length1 === 0) { coords1 = this.start1 + ',0'; diff --git a/lua/diff_match_patch.lua b/lua/diff_match_patch.lua index a2ae2162..c92b4f42 100644 --- a/lua/diff_match_patch.lua +++ b/lua/diff_match_patch.lua @@ -58,9 +58,10 @@ local function indexOf(a, b, start) return strfind(a, b, start, true) end -local htmlEncode_pattern = '[&<>\n]' +local htmlEncode_pattern = '[&<>\n\t ]' local htmlEncode_replace = { - ['&'] = '&', ['<'] = '<', ['>'] = '>', ['\n'] = '¶
' + ['&'] = '&', ['<'] = '<', ['>'] = '>', ['\n'] = '¶
', + ['\t'] = ' ', [' '] = ' ' } -- Public API Functions diff --git a/objectivec/DiffMatchPatch.m b/objectivec/DiffMatchPatch.m index 0c56201d..e390a485 100755 --- a/objectivec/DiffMatchPatch.m +++ b/objectivec/DiffMatchPatch.m @@ -1239,6 +1239,8 @@ - (NSString *)diff_prettyHtml:(NSMutableArray *)diffs; [text replaceOccurrencesOfString:@"<" withString:@"<" options:NSLiteralSearch range:NSMakeRange(0, text.length)]; [text replaceOccurrencesOfString:@">" withString:@">" options:NSLiteralSearch range:NSMakeRange(0, text.length)]; [text replaceOccurrencesOfString:@"\n" withString:@"¶
" options:NSLiteralSearch range:NSMakeRange(0, text.length)]; + [text replaceOccurrencesOfString:@"\t" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, text.length)]; + [text replaceOccurrencesOfString:@" " withString:@" " options:NSLiteralSearch range:NSMakeRange(0, text.length)]; switch (aDiff.operation) { case DIFF_INSERT: diff --git a/python2/diff_match_patch.py b/python2/diff_match_patch.py index 8b26125c..41492c05 100644 --- a/python2/diff_match_patch.py +++ b/python2/diff_match_patch.py @@ -1071,7 +1071,8 @@ def diff_prettyHtml(self, diffs): html = [] for (op, data) in diffs: text = (data.replace("&", "&").replace("<", "<") - .replace(">", ">").replace("\n", "¶
")) + .replace(">", ">").replace("\n", "¶
") + .replace("\t", " ").replace(" ", " ")) if op == self.DIFF_INSERT: html.append("%s" % text) elif op == self.DIFF_DELETE: diff --git a/python3/diff_match_patch.py b/python3/diff_match_patch.py index 3bf825c5..6bf42a25 100644 --- a/python3/diff_match_patch.py +++ b/python3/diff_match_patch.py @@ -1069,7 +1069,8 @@ def diff_prettyHtml(self, diffs): html = [] for (op, data) in diffs: text = (data.replace("&", "&").replace("<", "<") - .replace(">", ">").replace("\n", "¶
")) + .replace(">", ">").replace("\n", "¶
") + .replace("\t", " ").replace(" ", " ")) if op == self.DIFF_INSERT: html.append("%s" % text) elif op == self.DIFF_DELETE: