全文对比处理表格问题。

This commit is contained in:
wangzhijiang
2024-03-21 10:36:28 +08:00
parent 1e064b79e9
commit 7cf4ad2a09
@@ -2231,6 +2231,8 @@ public class DiffUtils {
public List<String> getHtmlDiffStr(String text1,String text2){
Map<String,String> replaceMap1 = new HashMap<>();
Map<String,String> replaceMap2 = new HashMap<>();
Map<String,String> replaceMap3 = new HashMap<>();
Map<String,String> replaceMap4 = new HashMap<>();
//text1 = text1.replaceAll("<img.*\\>", "");
int startIndex = text1.indexOf("<img");
int index = 0;
@@ -2257,6 +2259,31 @@ public class DiffUtils {
startIndex = text2.indexOf("<img");
}
startIndex = text1.indexOf("<table");
index = 0;
while (startIndex > -1) {
int endIndex = text1.indexOf("</table>", startIndex);
String subStr = text1.substring(startIndex, endIndex + 1);
String repStr = "<replaceTable_" + index + ">";
text1 = text1.replace(subStr, repStr);
replaceMap3.put(repStr,subStr);
index++;
startIndex = text1.indexOf("<table");
}
//text2 = text2.replaceAll("<img.*\\>", "");
startIndex = text2.indexOf("<table");
index = 0;
while (startIndex > -1) {
int endIndex = text2.indexOf("</table>", startIndex);
String subStr = text2.substring(startIndex, endIndex + 1);
String repStr = "<replaceTable_" + index + ">";
text2 = text2.replace(subStr, repStr);
replaceMap4.put(repStr,subStr);
index++;
startIndex = text2.indexOf("<table");
}
LinkedList<Diff> diffs = diff_main(text1, text2);
//定义输出结果
String LResultStr="";
@@ -2285,6 +2312,12 @@ public class DiffUtils {
for (String key:replaceMap2.keySet()) {
RResultStr = RResultStr.replace(key,replaceMap2.get(key));
}
for (String key:replaceMap3.keySet()) {
LResultStr = LResultStr.replace(key,replaceMap3.get(key));
}
for (String key:replaceMap4.keySet()) {
RResultStr = RResultStr.replace(key,replaceMap4.get(key));
}
result.add(LResultStr);
result.add(RResultStr);
return result;