Created
June 2, 2021 13:07
-
-
Save jn0/87f892ebce96e27b5c2571546570d9d6 to your computer and use it in GitHub Desktop.
markdown to PDF converter (and filter)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# sudo apt install them first: | |
# pandoc evince # pandoc + evince | |
# texlive-xetex # xelatex | |
# ttf-mscorefonts-installer # Georgia TTF | |
args=( "$@" ) | |
tmpd="$(mktemp -p /tmp -d md2pdf.$$.XXXXXXXXXX.tmp)" | |
trap 'rm -rf "$tmpd"' EXIT | |
chmod g+s "$tmpd" | |
STDIN="$tmpd/STDIN.md" | |
[ -t 0 -o -t 1 ] || { args+=( "$STDIN" ); cat > "$STDIN"; } | |
for f in "${args[@]}"; do | |
[ "$f" = "$STDIN" ] && as_filter=yes || as_filter=no | |
pdf="${f%%.md}.pdf" | |
pt="$(grep -m1 '^#' "$f" | sed -e 's/^#\+\s\+//' -)" | |
[ -z "$pt" ] && pt="$(basename "${f%%.md}")" | |
[ "$as_filter" = yes ] && echo -n "[-] -> [-]" >&2 || echo -n "[$f] -> [$pdf]" >&2 | |
echo " ($pt)" >&2 | |
sed -e 's/\.md)/\.pdf)/g' "$f" | | |
pandoc --from=markdown_github+smart+yaml_metadata_block \ | |
--metadata=pagetitle="$pt" \ | |
--standalone \ | |
--wrap=none \ | |
--variable=linkcolor=blue \ | |
--variable=fontsize=12pt \ | |
--variable=mainfont=Georgia \ | |
--pdf-engine=xelatex \ | |
--output="$pdf" | |
[ "$as_filter" = yes ] && cat "$pdf" | |
done | |
# EOF # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment