0

作为 web 应用程序的一部分,我需要显示一个 unix diff(我通过一个字符串作为一个 rest 调用得到它)并以颜色编码格式显示它。

我尝试使用diff2Html库,但它只接受 git 样式差异或统一差异格式。

这是 api 调用的输出

"2,4c2,4\n< 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 diff 的字符串版本:

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 工具可以接受这种格式的输入并美化它?

4

1 回答 1

0

这里是。

http://qiao.github.io/difflib.js/

difflib.unifiedDiff 函数运行良好。

于 2019-02-09T21:00:35.330 回答