htmldiff-js icon indicating copy to clipboard operation
htmldiff-js copied to clipboard

<p>

Open Czj1997-02 opened this issue 2 years ago • 0 comments

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)

Czj1997-02 avatar Oct 21 '22 06:10 Czj1997-02