Created
May 12, 2011 19:25
-
-
Save panozzaj/969250 to your computer and use it in GitHub Desktop.
Word diff two markdown files in git and output the result formatted for Pandoc CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
filename=$1 | |
if [[ -z $filename ]] || [[ $filename == 'help' ]] | |
then | |
echo 'usage: diff_script file.markdown [old_revision] [new_revision]' | |
echo ' old_revision defaults to HEAD^' | |
echo ' new_revision defaults to current file (HEAD if unchanged)' | |
exit | |
fi | |
old_revision=$2 | |
new_revision=$3 | |
old_filename=`mktemp` | |
new_filename=`mktemp` | |
if [ -z $old_revision ] # if old revision specified | |
then | |
git show "HEAD^":$filename > $old_filename # just take previous revision | |
else | |
git show $old_revision:$filename > $old_filename # find that specific revision in history and use it | |
fi | |
if [ -z $new_revision ] # if new revision specified | |
then | |
cp $filename $new_filename # just take current version in the file system | |
else | |
git show $new_revision:$filename > $new_filename # find that specific revision in history and use it | |
fi | |
# consider stripping Markdown comments here | |
# actual diffing of the files | |
diff_markdown_filename=`mktemp` | |
echo "diff markdown filename: $diff_markdown_filename" | |
wdiff -w '<span class="diff-added">' -x '</span>' -y '<span class="diff-removed">' -z '</span>' $new_filename $old_filename > $diff_markdown_filename | |
pandoc -s --html5 --smart -c my.css $diff_markdown_filename | |
# cleanup | |
# commenting out for debugging and they are temp files anyway | |
#rm $old_filename $new_filename $diff_markdown_filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment