Diffing lines within a string

179 views
Skip to first unread message

Danielle Greenberg

unread,
Jun 15, 2020, 5:03:19 PM6/15/20
to Diff Match Patch
Using the example from https://github.com/google/diff-match-patch/wiki/Line-or-Word-Diffs


const text1 = "this is first document\r\n111\r\n222\r\n333\r\n";
const text2 = "this is second document\r\n444\r\n555\r\n666\r\n";

var a = dmp.diff_linesToChars_(text1, text2);
var lineText1 = a.chars1;
var lineText2 = a.chars2;
var lineArray = a.lineArray;
var diffs = dmp.diff_main(lineText1, lineText2, false);
dmp
.diff_cleanupSemantic(diffs);
dmp
.diff_charsToLines_(diffs, lineArray);
console
.log(diffs);

I get:

[Array[2], Array[2]]
  1. 0: Array[2]
  2. 1: Array[2]

It looks like I get the difference per the whole string and I need to compare the lines within the string, the line parts(within the \r\n),
How is that achieved?
Reply all
Reply to author
Forward
0 new messages