Advertisement
difusal

Untitled

Aug 30th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. var dmp = new diff_match_patch();
  2.  
  3. function myDiff(doc1, doc2) {
  4. return dmp.diff_main(doc1, doc2);
  5. }
  6.  
  7. function myPatch(doc, diffs) {
  8. return dmp.patch_make(doc, diffs);
  9. }
  10.  
  11. function myApplyPatchToDoc(doc, patches) {
  12. return dmp.patch_apply(patches, doc)[0];
  13. }
  14.  
  15. function launch() {
  16. var text1 = document.getElementById('text1').value;
  17. var text2 = document.getElementById('text2').value;
  18.  
  19. var diffs = myDiff(text1, text2);
  20.  
  21. /*
  22. * Add diffs (Edit obj) to the Edits stack here...
  23. */
  24. //console.log(diffs);
  25.  
  26. var str = "I am the very model of a modern Major-General,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.";
  27.  
  28. // calculate patches
  29. var patches = myPatch(str, diffs);
  30.  
  31. // results
  32. console.log(myApplyPatchToDoc(str, patches));
  33.  
  34. var ds = dmp.diff_prettyHtml(diffs);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement