git.iko.soy/typeable/pandoc
on master help sign in
Improve diff-docx.sh -> diff-zip.sh.

It now can be used on odts, docx, or epubs.

commit83a0104d5bcfbc3eab3f9846feac2bfa6712d3c2 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 10 Jul 2019, 20:53 (7 years ago) parent2c2d4e2
2 files changed+26−22
tools/diff-docx.sh−22 tools/diff-zip.sh+26
tools/diff-docx.shdeleted−22
@@ -1,22 +0,0 @@
1−#!/bin/sh
2−f1="$1"
3−f2="$2"
4−test -f "$f1" -a -f "$f2" || {
5− echo "Usage: diff-docx first.docx second.docx" && exit 1
6−}
7−WORKDIR=$(mktemp -d -t diff-docx)
8−trap "{ rm -r $WORKDIR; }" EXIT
9−unzip -q -d "$WORKDIR/a" "$f1"
10−unzip -q -d "$WORKDIR/b" "$f2"
11−cd "$WORKDIR"
12−mkdir tidy
13−for x in a b; do
14− cp -r $x tidy/
15− find $x -iname '*.xml' -exec sh -c 'mkdir -p "$(dirname tidy/$1)" && tidy -q -xml -utf8 -i "$1" > "tidy/$1"' _ {} \;
16− find $x -iname '*.rels' -exec sh -c 'mkdir -p "$(dirname tidy/$1)" && tidy -q -xml -utf8 -i "$1" > "tidy/$1"' _ {} \;
17−done
18−cd tidy
19−mkdir c
20−cp -r a/* c/
21−cp -r b/* c/
22−find c -type f -exec sh -c 'echo "\033[1m=== ${1#*/} ===\033[0m" ; diff -u "a/${1#*/}" "b/${1#*/}" 2>&1' _ {} \;
tools/diff-zip.shnew file+26
@@ -0,0 +1,26 @@
1+#!/bin/sh
2+
3+# This script allows you to compare two epub, odt, or docx
4+# containers, ignoring insignificant formatting differences
5+# in the XML contents.
6+
7+f1="$1"
8+f2="$2"
9+test -f "$f1" -a -f "$f2" || {
10+ echo "Usage: diff-zip firstfile secondfile" && exit 1
11+}
12+WORKDIR=$(mktemp -d -t diff-zip)
13+trap "{ rm -r $WORKDIR; }" EXIT
14+unzip -q -d "$WORKDIR/a" "$f1"
15+unzip -q -d "$WORKDIR/b" "$f2"
16+cd "$WORKDIR"
17+mkdir tidy
18+for x in a b; do
19+ cp -r $x tidy/
20+ find -E $x -iregex '.*\.(xhtml|xml|rdf|rels)' -exec sh -c 'mkdir -p "$(dirname tidy/$1)" && tidy -q -xml -utf8 -i "$1" > "tidy/$1"' _ {} \;
21+done
22+cd tidy
23+mkdir c
24+cp -r a/* c/
25+cp -r b/* c/
26+find c -type f -exec sh -c 'echo "\033[1m=== ${1#*/} ===\033[0m" ; diff -u "a/${1#*/}" "b/${1#*/}" 2>&1' _ {} \;