Skip to content

Instantly share code, notes, and snippets.

@FlorianHeigl
Last active January 22, 2019 23:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlorianHeigl/773411d0b2d180d5974508d4b716256a to your computer and use it in GitHub Desktop.
Save FlorianHeigl/773411d0b2d180d5974508d4b716256a to your computer and use it in GitHub Desktop.
pandoc pdf script
#!/bin/bash -u
# you can find the css here:
# https://gist.githubusercontent.com/killercup/5917178/raw/40840de5352083adb2693dc742e9f75dbb18650f/pandoc.css
## html creation via pandoc and LaTex
generate_html() {
# this generates more valid html but gives us a big fat h1 title
# no idea how to get the %title defined in markdown
#pandoc ${1} --metadata=title="based on file $(basename $2)" -s -t html5 --css="$(dirname $0)/pandoc.css" -o ${2}
# this version just supresses the warning and the resulting file looks as it should
pandoc ${1} --quiet -s -t html5 --css="$(dirname $0)/pandoc.css" -o ${2}
}
format_htmlname() {
unset htmlfile
htmlfile=$(echo ${1} | sed 's/\.md/\.html/') &&
export htmlfile
}
check_html() {
## if no html exists, or is outdated, create it
if ! [ -x ${htmlfile} ] || [ ${htmlfile} -ot ${mdfile} ]; then
generate_html ${mdfile} ${htmlfile}
fi
}
if [ $# -eq 1 ] && test -r $1 ; then
mdfile=$1
format_htmlname $mdfile &&
check_html
exit $?
fi
## loop over all files in markdown format
for mdfile in $(find . -type f -name "*md") ; do
format_htmlname $mdfile &&
check_html || exit $?
done
#!/bin/bash -u
## pdf creation via pandoc and LaTex
generate_pdf() {
pandoc ${1} --pdf-engine=pdflatex -o ${2}
}
format_pdfname() {
unset pdffile
pdffile=$(echo ${1} | sed 's/\.md/\.pdf/') &&
export pdffile
}
check_pdf() {
## if no pdf exists, or is outdated, create it
if ! [ -x ${pdffile} ] || [ ${pdffile} -ot ${mdfile} ]; then
generate_pdf ${mdfile} ${pdffile}
fi
}
if [ $# -eq 1 ] && test -r $1 ; then
mdfile=$1
format_pdfname $mdfile &&
check_pdf
exit $?
fi
## loop over all files in markdown format
for mdfile in $(find . -type f -name "*md") ; do
format_pdfname $mdfile &&
check_pdf || exit $?
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment