booxdown 1.1 KB

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