diff options
| -rwxr-xr-x | mdtopdf | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# @describe Convert markdown file to PDF +# @meta require-tools pandoc +# @arg inputfile+ markdown file +# @option --font[?`_choice_font_fn`] font (default Arial) +# @option --from[?`_choice_from_fn`] from format +# @option --pdf-engine[typst|xelatex] PDF engine + +# Specification: https://github.com/sigoden/argc/blob/main/docs/specification.md + +_choice_font_fn() { + fc-list : family +} + +_choice_from_fn() { + pandoc --list-input-formats +} + +find_pdf_engine() { + for engine in typst xelatex; do + if command -v "$engine" &>/dev/null; then + echo "$engine" + exit + fi + done + exit 2 +} + +main() { + local engine + local from + engine=${argc_pdf_engine:-$(find_pdf_engine)} + from=${argc_from:-markdown} + for infile in "${argc_inputfile[@]?}"; do + outfile="${infile%.*}.pdf" + pandoc --from="$from" --pdf-engine="$engine" -V mainfont="${argc_font:-Arial}" "$infile" -o "$outfile" + done +} + +eval "$(argc --argc-eval "$0" "$@")" |
