我想了解两个 HTML 字符串之间的差异(删除字符串和添加字符串)。diff 函数的函数必须给出如下结果:
String html1 = "<h1>foo foo </h1>";
String html2 = "<h1>foo baar </h1>";
private String diff(String html1, String html2){
...
// diff method should return following:
return "<h1>foo <span class = "deleted">foo</span> <span class = "added">baar </span> </h1>";
}
我试过 diff_match_patch 但它有 html 标签的问题。例子:
String html1 = "<ol><li>foo</li><li>baar</li></ol>"
String html2 = "<ol><li>AA</li></ol>"
diff_match_patch(html1, html2) gives the following diff string:
<ol>
<li>AA<del style="background:#ffe6e6;"></li>
<li>BB</del>
</li>
</ol>
它应该是:
<ol>
<li>AA</li>
<del style="background:#ffe6e6;"><li>BB</del>
</li>
</ol>