booxdown 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. highlight-style: monochrome
  34. citemethod: biblatex
  35. pdfa: true
  36. hyperrefoptions:
  37. - breaklinks=true
  38. - bookmarks=true
  39. EOF
  40. if [ $HAS_METADATA -eq 1 ] ; then
  41. cat $MDFILE | sed '1 d' >> $FILE
  42. else
  43. echo "..." >> $FILE
  44. cat $MDFILE >> $FILE
  45. fi
  46. echo "Processing file to PDF."
  47. pandoc -f markdown \
  48. -s -t pdf \
  49. --highlight-style monochrome \
  50. --pdf-engine='lualatex' \
  51. -o $PDFFILE \
  52. $FILE
  53. echo "Done."
  54. rm $FILE