3 # Convert diff output to colorized HTML.
4 # http://www.linuxjournal.com/content/convert-diff-output-colorized-html
5 # usage: diff -u v1.c v2.c | diff2html >v1-v2.html
10 <title>Colorized Diff</title>
13 .diffdiv { border: solid 1px black; }
14 .comment { color: gray; }
15 .diff { color: #8A2BE2; }
16 .minus3 { color: blue; }
17 .plus3 { color: maroon; }
19 .plus { color: green; background: #E7E7E7; }
20 .minus { color: red; background: #D7D7D7; }
21 .only { color: purple; }
27 echo -n '<span class="comment">'
37 # The -r option keeps the backslash from being an escape char.
42 # Get beginning of line to determine what type
50 # Determine HTML class to use.
51 if [[ "$t7" == 'Only in' ]]; then
53 if [[ $diffseen -eq 0 ]]; then
57 if [[ $lastonly -eq 0 ]]; then
61 if [[ $lastonly -eq 0 ]]; then
62 echo "<div class='diffdiv'>"
65 elif [[ "$t4" == 'diff' ]]; then
67 if [[ $diffseen -eq 0 ]]; then
73 echo "<div class='diffdiv'>"
75 elif [[ "$t3" == '+++' ]]; then
78 elif [[ "$t3" == '---' ]]; then
81 elif [[ "$t2" == '@@' ]]; then
84 elif [[ "$t1" == '+' ]]; then
87 elif [[ "$t1" == '-' ]]; then
95 # Convert &, <, > to HTML entities.
96 s
=$
(sed -e 's/\&/\&/g' -e 's/</\</g' -e 's/>/\>/g' <<<"$s")
97 if [[ $first -eq 1 ]]; then
104 if [[ "$cls" ]]; then
105 echo -n '<span class="'${cls}'">'${s}'</span>'
113 if [[ $diffseen -eq 0 && $onlyseen -eq 0 ]]; then
126 # vim: tabstop=4: shiftwidth=4: noexpandtab:
127 # kate: tab-width 4; indent-width 4; replace-tabs false;