forked from gzinck/uw-ethics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwdiff
executable file
·32 lines (24 loc) · 1 KB
/
pwdiff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# Adapted from https://github.com/jduckles/pwdiff
oldfile='temp-old.md'
newfile='temp-new.md'
# Remove all formatting from the files
cat $1 | sed 's/<span[^>]*>//g' | sed 's/<\/span>//g' | sed -r 's/<\/?[ib]>//g' > ${oldfile}
cat $2 | sed 's/<span[^>]*>//g' | sed 's/<\/span>//g' | sed -r 's/<\/?[ib]>//g' > ${newfile}
context_lines=65535 # Set to be very large to include whole document as output.
# Select the SED option for advanced regex. Could be -r or -E.
SED_OPTION=( -r )
if ! echo '<span className="test"># Test' | sed $SED_OPTION 's/(<span[^>]*>)(#+ |- )/\2\1/g' > /dev/null 2>&1; then
SED_OPTION=( -E )
fi
DIFF=`git diff -U${context_lines} --no-index --word-diff -- ${oldfile} ${newfile} |\
tail +6 |\
sed 's/\[-/<del>/g;s/-]/<\/del>/g;' |\
sed 's/{+/<span class="inserted-text">/g;s/+}/<\/span>/g;' |\
sed $SED_OPTION 's/(<span[^>]*>)(#+ |- )/\2\1/g'` # Move spans after head/bullet
if [ -z "$DIFF" ]; then
cat $newfile
else
echo "$DIFF"
fi
rm $oldfile $newfile