From 0ff7de22a75c8cf359bf090d11ce598dddf114f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Th=C3=A9r=C3=A8se=20Godefroy?= Date: Fri, 15 Aug 2014 01:20:20 +0200 Subject: [PATCH] fr/kitchen/color-wdiff: fix a few bugs, reword the explanations. --- fr/kitchen/color-wdiff | 200 ++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 125 deletions(-) diff --git a/fr/kitchen/color-wdiff b/fr/kitchen/color-wdiff index 7648a267..9d84eeec 100755 --- a/fr/kitchen/color-wdiff +++ b/fr/kitchen/color-wdiff @@ -1,132 +1,82 @@ #!/bin/bash -# color-wdiff visualizes the differences between 2 versions of the same page. -# This script was extracted from GNUN's GNUmakefile (function "mark-outdated") -# and adapted. GNUN (http://www.gnu.org/software/gnun/) is under GPLv3. - -# Howto: -# - The script is in [...]/enc/fr/kitchen. -# - cd to that directory and run: -# ./color-wdiff FILE1 FILE2 -# (FILE1 and FILE2 are the paths to the files to be compared.) -# - The diff file is created in the directory where FILE1 resides. +# NAME +# color-wdiff - visualize differences between text files + +# SYNOPSIS +# color-wdiff FILE0 FILE1 + +# DEPENDENCIES +# wdiff, reformat-html in $HOME/bin. + +# DESCRIPTION +# 1. If the input files are HTML, they are reformatted, to remove +# indentation among other things. +# 2. The markup is inactivated by replacing angle brackets with the +# corresponding entities. +# 3. The files are compared with wdiff, using options which label +# insertions and deletions. The labels are HTML tags with specific +# classes. +# 4. The diff is turned into a valid HTML page by adding the required +# markup, plus CSS style for the insertion and deletion classes. # -# For example, compare old and new versions of index.t.html: -# ./color-diff index.t.html index-new.t.html - -# Note: the diff is much easier to use if the HTML is not indented. -# Reformatting is done by the function "page_reformat", which leaves the -# original page intact. - - -file=$1 -file1=$2 -diff_file=${file%.html}-diff.html - -page_reformat () { - #reformats the original pages of emailselfdefense.fsf.org - - cp $1 $1.tmp - - # Remove javascript, which shouldn't be reformatted. - sed -i '/jquery-1.11.0.min.js/,$d' $1.tmp - - # Remove leading and trailing spaces/tabs. - sed -i 's,\t, ,g' $1.tmp - sed -i 's,^ *,,' $1.tmp - sed -i 's, *$,,' $1.tmp - - # Remove LF after . - sed -i '/<\/a>$/ {N; s,<\/a>\n\([^<]\),<\/a>\1,}' $1.tmp - - # One string per paragraph, header or list item. - for tag in li p strong a h3; do - sed -i "/<$tag[^>]*>$/ {N; s,\\n, ,}" $1.tmp - done - for tag in a strong; do - sed -i "/<\\/$tag>$/ {N; s,\\n, ,}" $1.tmp - done - # This command may need to be repeated. Adjust the number of repeats. This - # could be done by looping back to a sed marker, but a while loop seems - # quicker. - i=0 - while (( i < 2 )); do - sed -i '/[^<>]$/ {N; s,\([^<>]\)\n,\1 ,}' $1.tmp - let i=i+1 - done - - sed -i '/ \/>$/ {N; s,\( \/>\)\n,\1 ,}' $1.tmp - sed -i '/ ]*>$/ {N; s,\(]*>\)\n\([^<]\),\1 \2,}' $1.tmp - - # Make sure there is only one paragraph per string. This command may need to - # be repeated. Adjust the number of repeats. - i=0 - while (( i < 2 )); do - sed -i 's,

\(.\+\)$,

\n\1,' $1.tmp - let i=i+1 - done - - # Single out the tags which include p (will also work for pre). - sed -i 's,\(.\) <$tag,>\n<$tag," $1.tmp - done - # Remove leading and trailing spaces, double spaces and blank lines. - sed -i 's,^ *,,' $1.tmp - sed -i 's, *$,,' $1.tmp - sed -i 's, , ,g' $1.tmp - sed -i '/^$/d' $1.tmp - - # Fuse comment with

. - sed -i '/<\/p>$/ {N;s,\n\( @@ -147,10 +97,10 @@ wdiff --start-delete '' \ --end-delete '' \ --start-insert '' \ --end-insert '' \ - ${file}.tmp ${file1}.tmp >> $diff_file + ${f[0]} ${f[1]} >> $diff_file || true # Add the closing tags. -echo '' >> $diff_file +echo '' >> ${diff_file} -# Clean up. -rm -f ${file}.tmp ${file1}.tmp ${file}.r ${file1}.r +echo -e "\n The diff file is $diff_file." +close_term 0 -- 2.25.1