-
-
Save ecylmz/823003 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# markdown ile yazılan dosyalardan pdf üret. | |
# Örnek: <betik> ~/examples.md | |
PATH=/var/lib/gems/1.8/bin:$PATH | |
[ $# -gt 0 ] || { | |
echo >&2 "Kullanım: $0 < markdown dosyası>" | |
echo >&2 "Örnek: $0 ~/examples.md" | |
exit 1 | |
} | |
[ -n "$(which kramdown)" ] || { | |
echo >&2 "kramdown kurulu değil" | |
echo >&2 " sudo gem install kramdown" | |
exit 1 | |
} | |
[ -n "$(which pdflatex)" ] || { | |
echo >&2 "texlive kurulu değil" | |
echo >&2 " sudo apt-get install texlive" | |
exit 1 | |
} | |
INFILE="$(readlink -f "$1")" | |
[ -f "$INFILE" ] || { | |
echo >&2 "Yok böyle bir dosya: $INFILE" | |
exit 1 | |
} | |
BASE="$(basename "$INFILE")" | |
BASE="${BASE%%.*}" | |
TEMPDIR=$(mktemp -d) || exit 1 | |
trap 'err=$?; rm -rf $TEMPDIR; exit $err' EXIT HUP QUIT INT TERM | |
ORIGDIR="$PWD"; ( | |
cd "$TEMPDIR" && kramdown "${INFILE}" -o latex --template document >"${BASE}.tex" | |
TEXINPUTS=$ORIGDIR:$TEXINPUTS: pdflatex -interaction=batchmode "${BASE}.tex" >/dev/null 2>&1 | |
) && { | |
OUTFILE="${TEMPDIR}/${BASE}.pdf" | |
if [ -f "$OUTFILE" ]; then | |
mv "$OUTFILE" . | |
echo >&2 "${BASE}.pdf hazır." | |
exit 0 | |
fi | |
} | |
echo >&2 "pdf üretilemedi." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment