Monday, 30 May 2016

Produce html diff with diff2html-cli

It is handy to do with one nice JavaScript tool, which works on any platform:

> npm install diff2html-cli
> diff -u fileA.txt fileB.txt | diff2html -F diff.html -i stdin

It is important to have -u option for diff command you pipe into diff2html, because it produces unified diff and diff2html expects unified diff.

It is also possible to do these two commands separatedly, without piping:

Write diff of a and b into a-b.diff file:
> diff -u a.txt b.txt > a-b.diff

Produce HTML file from the diff file:
> diff2html -F a-b.html -i file -- a-b.diff