Skip to content

Instantly share code, notes, and snippets.

@danman01
Created September 21, 2015 14:08
Show Gist options
  • Save danman01/d7576fe229416867fa05 to your computer and use it in GitHub Desktop.
Save danman01/d7576fe229416867fa05 to your computer and use it in GitHub Desktop.
#!/bin/sh
pdf_stylesheet="/Users/dkirschner/dev/mapr/apache_spark/ebook/spark-book-theme/pdf/pdf.css"
theme_stylesheet="/Users/dkirschner/dev/mapr/apache_spark/ebook/spark-ebook/theme/pdf/pdf.css"
print_stylesheet="/Users/dkirschner/dev/mapr/apache_spark/ebook/spark-book-theme/pdf/pdf_print.css"
USAGE="Usage: -f markdown file with md file ending, -o optional output file with pdf ending, -p anything here will turn on print mode, -? or -h prints usage"
while getopts “ht:f:o:p” OPTION
do
case $OPTION in
h)
echo $USAGE
exit 1
;;
f)
markdown=$OPTARG
;;
o)
pdf=$OPTARG
;;
p)
PRINT=1
;;
?)
echo $USAGE
exit
;;
esac
done
if [[ -z $markdown ]]
then
echo $USAGE
exit 1
fi
# convert supplied markdown file to html using prince
# convert markdown to html
html=$(echo "$markdown" | sed 's/\.md/\.html/')
echo "converting markdown to html file which will be $html..."
`pandoc $markdown -o $html`
if [[ -z $pdf ]]
then
pdf=$(echo "$html" | sed 's/html/pdf/')
fi
echo "converting html to pdf which will be $pdf"
# convert html to pdf
if [ -z $PRINT ]
then
echo "generating web version of pdf..."
prince $html -o $pdf -s $pdf_stylesheet -s $theme_stylesheet
else
echo "generating print version of pdf..."
prince $html -o $pdf -s $pdf_stylesheet -s $theme_stylesheet -s $print_stylesheet
fi
# remove the html file we generated earlier
rm $html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment