git.iko.soy/typeable/pandoc
on master help sign in
Add diff-docx.sh to tools.
commit2c2d4e2138c85f4669c2c7f8868697c9047bbd00 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 10 Jul 2019, 20:28 (7 years ago) parent1d9ff85
1 file changed+22
tools/diff-docx.sh+22
tools/diff-docx.shnew file+22
@@ -0,0 +1,22 @@
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' _ {} \;