htmldiff-js
htmldiff-js copied to clipboard
<p>
Thanks for the contribution of the author. I have a good idea to deal with the problem of
tags. the problem may be caused by incomplete regular matching, I found that thetag has a similar problem,
so it can be solved in this way.replace the label with regular before comparison
toHtml(text) {
var reg1 = /<p/g;
var reg2 = /<\/p>/g;
var reg3 = /<strong/g;
var reg4 = /<\/strong>/g;
text = text.replace(reg1, "<div class='type-p' ");
text = text.replace(reg2, "</div><div class='end-p'></div>");
text = text.replace(reg3, "<div class='type-strong' ");
text = text.replace(reg4, "</div><div class='end-strong'></div>");
return text;
},
diffhtml = HtmlDiff.execute(this.toHtml(actionData),this.toHtml(newData))
replaced after comparison
toEditor(text) {
// 在转换后把p标签和strong标签换回来
var reg5 = /<div class='type-p' /g;
var reg6 = /<\/div><div class=\'end-p\'><\/div>/g;
var reg7 = /<div class='type-strong' /g;
var reg8 = /<\/div><div class=\'end-strong\'><\/div>/g;
text = text.replace(reg5, "<p");
text = text.replace(reg6, "</p>");
text = text.replace(reg7, "<strong");
text = text.replace(reg8, "</strong>");
return text;
},
diffhtml = this.toEditor(diffhtml)