From f275dd4fbac31f86e4efa7cb3bb2e904b89da008 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Th=C3=A9r=C3=A8se=20Godefroy?=
Date: Sun, 27 Jul 2014 23:07:29 +0200
Subject: [PATCH] fr: script to visualize differences between 2 pages.
---
fr/kitchen/color-wdiff | 156 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 156 insertions(+)
create mode 100755 fr/kitchen/color-wdiff
diff --git a/fr/kitchen/color-wdiff b/fr/kitchen/color-wdiff
new file mode 100755
index 0000000..7648a26
--- /dev/null
+++ b/fr/kitchen/color-wdiff
@@ -0,0 +1,156 @@
+#!/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.
+#
+# 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\(
+
+
+
+${diff_file##*\/}
+
+
+EOF
+
+# Run wdiff with options to add the proper markup at the beginning and end of
+# deletions and insertions.
+wdiff --start-delete '' \
+ --end-delete '' \
+ --start-insert '' \
+ --end-insert '' \
+ ${file}.tmp ${file1}.tmp >> $diff_file
+
+# Add the closing tags.
+echo '
' >> $diff_file
+
+# Clean up.
+rm -f ${file}.tmp ${file1}.tmp ${file}.r ${file1}.r
--
2.25.1