我正在比较两个 json 对象,然后使用 Diff2Html 渲染它们
首先,我使用 Diff libbary
生成差异字符串const diffString = diff.createTwoFilesPatch('file', 'file', this.reference, this.result, undefined, undefined, {
context: Number.MAX_SAFE_INTEGER,
});
当两个比较的字符串相等时,我得到一个空字符串,完全正确:
"Index: file\n===================================================================\n--- file\n+++ file\n"
我渲染字符串:
const div: HTMLElement = this.diffDiv.nativeElement;
const diff2htmlUi = new Diff2HtmlUI(div, diffString, this.configuration);
diff2htmlUi.draw();
然后 Diff2Html 渲染此屏幕:
我希望渲染所有相同的字符串对象。我没找到办法
我遇到了同样的问题,只是通过稍微更改 diff.js (在本例中提到)的代码来解决它
你必须改变
structuredPatch
功能
在该函数中查找
// Identical context lines. Track line changes
此注释并且
将条件更改为始终为真。
// Identical context lines. Track line changes
if (oldRangeStart || true ) {