Skip to content

Instantly share code, notes, and snippets.

@agh1
Created June 20, 2020 22:20
Show Gist options
  • Save agh1/f82858f4351f201a2b154b4735b3c1bf to your computer and use it in GitHub Desktop.
Save agh1/f82858f4351f201a2b154b4735b3c1bf to your computer and use it in GitHub Desktop.
Markdown to HTML to PDF
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
sourcefile=$1
if [ -z $1 ] ; then
if ! [ -f $DIR/letter.md ]; then
echo 'You must set up your letter as `letter.md` or specify a file name.'
exit 1;
fi
sourcefile="$DIR/letter.md"
elif ! [ -f $1 ]; then
echo "No file can be found at $1."
exit 1;
fi
ts=`date +%s`
filename=letter-$ts
i=0
while [ -f /tmp/$filename.pdf ]; do
filename="letter-$ts-$i"
i=$[$i+1]
done
cat $DIR/resources/header.md $sourcefile | pandoc -f markdown -s -t html -o $DIR/.lettergen.html
smartypants $DIR/.lettergen.html > $DIR/.lettergen.smart.html
weasyprint $DIR/.lettergen.smart.html /tmp/$filename.pdf
rm $DIR/.lettergen.*html
/usr/bin/env xdg-open /tmp/$filename.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment