aboutsummaryrefslogtreecommitdiff
path: root/src/wrappers/markdown2pdf.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/wrappers/markdown2pdf.in')
-rw-r--r--src/wrappers/markdown2pdf.in35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/wrappers/markdown2pdf.in b/src/wrappers/markdown2pdf.in
index 90c5e6bb1..aaae07184 100644
--- a/src/wrappers/markdown2pdf.in
+++ b/src/wrappers/markdown2pdf.in
@@ -1,6 +1,7 @@
#!/bin/sh -e
REQUIRED="pdflatex"
+SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
### common.sh
@@ -8,27 +9,25 @@ REQUIRED="pdflatex"
texname=output
logfile=$THIS_TEMPDIR/log
+origdir=$(pwd)
-if ! pandoc -s -d -r markdown -w latex "$@" >$THIS_TEMPDIR/$texname.tex \
-2>$logfile; then
- [ -f $logfile ] && sed -e 's/^pandoc/markdown2pdf/g' \
- -e '/^INPUT=/d' -e '/^OUTPUT=/d' \
- -e '/^[[:space:]]*\(-f\|-t\|-s\|-R\|-S\|-m\|-i\|-c\|-T\|-D\|-d\)/,/./d'\
- -e 's/(implies -s)//g' $logfile >&2
- exit 1
-fi
+pandoc -s -r markdown -w latex "$@" -o - >$THIS_TEMPDIR/$texname.tex \
+2>$logfile
-outfile="$(sed -ne 's/^OUTPUT=//p' $logfile)"
-IFS="$NEWLINE"
-set -- $(sed -ne 's/^INPUT=//p' $logfile)
-firstinfilebase="${1%.*}"
-defaultdest="${firstinfilebase:-stdin}.pdf"
-destname="${outfile:-$defaultdest}"
+if [ "$OUTPUT" = "-" ]; then
+ firstinfile="$(echo $ARGS | sed -ne '1p')"
+ firstinfilebase="${firstinfile%.*}"
+ destname="${firstinfilebase:-stdin}.pdf"
+else
+ destname="$OUTPUT"
+fi
(
cd $THIS_TEMPDIR
- if ! pdflatex -interaction=batchmode $texname.tex >/dev/null 2>&1; then
- err "${THIS}: pdfLaTeX error context:"
+ TEXINPUTS=$TEXINPUTS:$origdir pdflatex -interaction=batchmode \
+ $texname.tex >/dev/null 2>&1 || {
+ errorcode=$?
+ err "${THIS}: pdfLaTeX error context:"
sed -ne '/^!/,/^[[:space:]]*$/p' \
-ne '/^[Ll]a[Tt]e[Xx] [Ww]arning/,/^[[:space:]]*$/p' \
-ne '/^[Ee]rror/,/^[[:space:]]*$/p' $texname.log >&2
@@ -40,8 +39,8 @@ destname="${outfile:-$defaultdest}"
err "${THIS}: Please install the 'fancyvrb' package from CTAN:"
err " http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/"
fi
- exit 1
- fi
+ exit $errorcode
+ }
) || exit $?
is_target_exists=