aboutsummaryrefslogtreecommitdiff
path: root/tools/diff-zip.sh
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-07-10 20:53:40 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-07-10 20:53:40 -0700
commit83a0104d5bcfbc3eab3f9846feac2bfa6712d3c2 (patch)
treedccd93be2e14053d099ae7aa4793ec5591a989d7 /tools/diff-zip.sh
parent2c2d4e2138c85f4669c2c7f8868697c9047bbd00 (diff)
downloadpandoc-83a0104d5bcfbc3eab3f9846feac2bfa6712d3c2.tar.gz
Improve diff-docx.sh -> diff-zip.sh.
It now can be used on odts, docx, or epubs.
Diffstat (limited to 'tools/diff-zip.sh')
-rwxr-xr-xtools/diff-zip.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/diff-zip.sh b/tools/diff-zip.sh
new file mode 100755
index 000000000..9ac4cf621
--- /dev/null
+++ b/tools/diff-zip.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# This script allows you to compare two epub, odt, or docx
+# containers, ignoring insignificant formatting differences
+# in the XML contents.
+
+f1="$1"
+f2="$2"
+test -f "$f1" -a -f "$f2" || {
+ echo "Usage: diff-zip firstfile secondfile" && exit 1
+}
+WORKDIR=$(mktemp -d -t diff-zip)
+trap "{ rm -r $WORKDIR; }" EXIT
+unzip -q -d "$WORKDIR/a" "$f1"
+unzip -q -d "$WORKDIR/b" "$f2"
+cd "$WORKDIR"
+mkdir tidy
+for x in a b; do
+ cp -r $x tidy/
+ find -E $x -iregex '.*\.(xhtml|xml|rdf|rels)' -exec sh -c 'mkdir -p "$(dirname tidy/$1)" && tidy -q -xml -utf8 -i "$1" > "tidy/$1"' _ {} \;
+done
+cd tidy
+mkdir c
+cp -r a/* c/
+cp -r b/* c/
+find c -type f -exec sh -c 'echo "\033[1m=== ${1#*/} ===\033[0m" ; diff -u "a/${1#*/}" "b/${1#*/}" 2>&1' _ {} \;