作为Web应用程序的一部分,我需要显示一个unix diff(我通过休息调用以字符串形式获得(并以颜色编码格式显示它。
我尝试使用 diff2Html 库,但它只接受 git 样式差异或统一差异格式。
这是 api 调用的输出
"2,4c2,4n< I need to run the laundry.n< I need to wash the dog.n< I need to get the car detailed.n---n> I need to do the laundry.n> I need to wash the car.n> I need to get the dog detailed."
这是这个 unix 差异的字符串版本:
2,4c2,4
< I need to run the laundry.
< I need to wash the dog.
< I need to get the car detailed.
---
> I need to do the laundry.
> I need to wash the car.
> I need to get the dog detailed.
是否有工具可以将此输出转换为统一格式,或者可以使用此格式的输入对其进行美化的 JavaScript 工具?
来了。
http://qiao.github.io/difflib.js/
difflib.unifiedDiff函数运行良好。