解析unix样式diff并使用Javascript

时间:2018-03-12 08:42:19

标签: javascript diff diff2html

作为网络应用程序的一部分,我需要显示一个unix diff(我将其作为一个字符串进行休息调用)并以彩色编码格式显示它。

我尝试使用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工具?

1 个答案:

答案 0 :(得分:0)

在这里。

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

difflib.unifiedDiff函数效果很好。