diff options
author | Jonas Smedegaard <dr@jones.dk> | 2013-04-21 15:30:38 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2013-04-21 15:30:38 +0200 |
commit | ccc374ecd0eafd67e73b80201eb1c451700c106a (patch) | |
tree | 20c3c67aeb256675b17405623b32a517ac459c15 /localworddiff | |
parent | 03b66fd27b701379af23c44c11bd6b1a408c5633 (diff) |
Add Word diff script.
Diffstat (limited to 'localworddiff')
-rwxr-xr-x | localworddiff | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/localworddiff b/localworddiff new file mode 100755 index 0000000..a1ec03a --- /dev/null +++ b/localworddiff @@ -0,0 +1,67 @@ +#!/bin/sh +# +# Copyright © 2013 Jonas Smedegaard <dr@jones.dk> +# Description: Generate word-based diff for console or web +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# Depends: libtext-worddiff-perl (>= 0.08) +# +# TODO: rewrite as Perl script, using HTML::HTML5::Builder + +set -e + +if [ -z "$3" ]; then + perl -MText::WordDiff -E 'say word_diff "'"$1"'", "'"$2"'", { STYLE => 'ANSIColor' }' + exit +fi + +cat > "$3" <<EOF +<!DOCTYPE html> +<html> +<head> +<link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css" /> +<style> +.fileheader { + display: none; + visibility: hidden; +} +.file { + float: left; + width: 49%; +} +.file .hunk { + float: right; + width: 90%; +} +.file .hunk del, +.file .hunk ins { + font-weight: bold; +} +.file .hunk del { + color: darkred; +} +.file .hunk ins { + color: darkgreen; +} + +</style> +</head> +<body> +EOF +perl -MText::WordDiff -E 'say word_diff "'"$1"'", "'"$2"'", { STYLE => 'HTMLTwoLines' }' >> "$3" +cat >> "$3" <<EOF +</body> +</html> +EOF |