Parse a unix style diff and show it as a color coded HTML using Javascript

489 Views Asked by At

As a part of a web app, I need to display a unix diff (which I'm getting through a rest call as a string) and display it in a color coded format.

I've tried to use diff2Html library but it only accepts git style diffs or unified diff formats.

Here's the output from the api call

"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."

Which is a string version of this 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.

Is there a tool to either convert this output to a unified format, or a javascript tool that takes input in this format and prettifies it?

1

There are 1 best solutions below

0
On

Here it is.

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

difflib.unifiedDiff function works well.