Text Version Comparison in FCKEditor

I use the Fck editor to write content. We save the text as versions in db. I want to highlight these changes in versions when loading text in the FCK editor.

How to compare text ....

How to show any text that has been deleted in scroll mode.

Please help me/...

+6
source share
1 answer

Try the Google diff-patch algorithm http://code.google.com/p/google-diff-match-patch/

Take the previous and current version of the text and save it in two parameters. Pass two parameters to the following function.

function diffString(o, n) { o = o.replace(/<[^<|>]+?>|&nbsp;/gi, ''); n = n.replace(/<[^<|>]+?>|&nbsp;/gi, ''); var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/)); var str = ""; var oSpace = o.match(/\s+/g); if (oSpace == null) { oSpace = ["\n"]; } else { oSpace.push("\n"); } var nSpace = n.match(/\s+/g); if (nSpace == null) { nSpace = ["\n"]; } else { nSpace.push("\n"); } if (out.n.length == 0) { for (var i = 0; i < out.o.length; i++) { str += '<span style="background-color:#F00;"><del>' + escape(out.o[i]) + oSpace[i] + "</del></span>"; } } else { if (out.n[0].text == null) { for (n = 0; n < out.o.length && out.o[n].text == null; n++) { str += '<span style="background-color:#F00;"><del>' + escape(out.o[n]) + oSpace[n] + "</del></span>"; } } for (var i = 0; i < out.n.length; i++) { if (out.n[i].text == null) { str += '<span style="background-color:#0C0;"><ins>' + escape(out.n[i]) + nSpace[i] + "</ins></span>"; } else { var pre = ""; for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++) { pre += '<span style="background-color:#F00;"><del>' + escape(out.o[n]) + oSpace[n] + "</del></span>"; } str += " " + out.n[i].text + nSpace[i] + pre; } } } return str; } 

this returns an html in which the new text is marked with green and the deleted text as red + crossed out.

+5
source

All Articles