booxdown 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. if [ $# -lt 1 ] ; then
  5. echo "$(basename $0) MARKDOWN-FILE+" >&2
  6. exit 1
  7. fi
  8. while (( "$#" )); do
  9. MDFILE=$1
  10. echo "Processing ${MDFILE}."
  11. PDFFILE=$(basename $MDFILE .md).pdf
  12. FILE=$(mktemp XXXXXXXXXX-${MDFILE})
  13. HAS_METADATA=0
  14. if head -n 1 ${MDFILE} | grep -- '---' > /dev/null ; then
  15. echo "Metadata Block Found"
  16. HAS_METADATA=1
  17. fi
  18. cat <<EOF >> $FILE
  19. ---
  20. documentclass: scrartcl
  21. classoption:
  22. - DIV=14
  23. papersize: a5
  24. fontsize: 10pt
  25. mainfont: LucidaBrightOT
  26. mainFontOptions:
  27. - Numbers=OldStyle
  28. sansfont: LucidaSansOT
  29. mathFont: LucidaBrightMathOT
  30. monofont: IBMPlexMono
  31. monofontoptions:
  32. - Scale=MatchLowercase
  33. - StylisticSet=3
  34. csquotes: true
  35. links-as-notes: true
  36. highlight-style: monochrome
  37. citemethod: biblatex
  38. toc: true
  39. pdfa: true
  40. hyperrefoptions:
  41. - breaklinks=true
  42. - bookmarks=true
  43. EOF
  44. if [ $HAS_METADATA -eq 1 ] ; then
  45. cat $MDFILE | sed '1 d' >> $FILE
  46. else
  47. echo "..." >> $FILE
  48. cat $MDFILE >> $FILE
  49. fi
  50. echo "Processing file to PDF."
  51. pandoc -f markdown \
  52. -s -t pdf \
  53. --highlight-style monochrome \
  54. --pdf-engine='lualatex' \
  55. -o $PDFFILE \
  56. $FILE
  57. echo "Done."
  58. rm $FILE
  59. shift
  60. done