You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 5, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 5, 2024. It is now read-only.
could generate something like git diff unified format by diff-match-patch? #114
I was wonder how could diff-match-patch generate a unified formate, so that we could use this unified formate to generate a beautiful diff side-by-side using [diff2html]https://github.com/rtfpessoa/diff2html
For now, the text string generated by method patch_toText, could not be parsed because it's not a standard formate like what git diff and linux diff command diff -u -N file1 file2.
Could anyone be helpful and tell me how to solve this issue? Much appriciated if anyone could help~
hey everyone, so I wanted to see if it's doable and after a little bit of research here and on the diff2html GitHub, I found this comment
var dmp = new diff_match_patch();
var a = dmp.diff_linesToChars_(firstDescribe, secondDescribe);
var lineText1 = a.chars1;
var lineText2 = a.chars2;
var lineArray = a.lineArray;
var diffs = dmp.diff_main(lineText1, lineText2, false);
dmp.diff_charsToLines_(diffs, lineArray);
console.info(diffs);
let patchMake = dmp.patch_make(firstDescribe,diffs);
let patchToText = dmp.patch_toText(patchMake);
Then patchToText can be used for diff2html
However, that is only solving only a portion of the problem, diff2html requires a Git diff format and that requires file a and b to be part of the git diff, if I simply add it as prefix then it works. It's a bit hacky but hey it works, so... :)
So it works even if it's a bit hacky, if someone else find a better and more elegant way of doing it then please post your answer. Also another thing to note is that the text might need some escaping or decoding since we can see in the print screen that carriage return were convert to %0A, I would prefer to have diff2html detect this as a new line really, so it needs a bit of adjustment but at least it kinda work.
Activity
Lo-pez commentedon May 17, 2022
Hey were you able to solve this?
christiankyte commentedon Mar 29, 2023
Was this solved?
liudonghua123 commentedon May 29, 2023
any updates?
ghiscoding commentedon Jun 13, 2024
hey everyone, so I wanted to see if it's doable and after a little bit of research here and on the diff2html GitHub, I found this comment
However, that is only solving only a portion of the problem, diff2html requires a Git diff format and that requires file
aandbto be part of the git diff, if I simply add it as prefix then it works. It's a bit hacky but hey it works, so... :)HTML Preview
Conclusion
So it works even if it's a bit hacky, if someone else find a better and more elegant way of doing it then please post your answer. Also another thing to note is that the text might need some escaping or decoding since we can see in the print screen that carriage return were convert to
%0A, I would prefer to have diff2html detect this as a new line really, so it needs a bit of adjustment but at least it kinda work.