aboutsummaryrefslogtreecommitdiff
path: root/src/wrappers/markdown2pdf.in
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-22 20:16:03 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-22 20:16:03 +0000
commitd829c4820adbe7a7634f1c1d825d0d206512e6e7 (patch)
tree2de3d3459e6f2788b3a9aede93add68503f5a588 /src/wrappers/markdown2pdf.in
parentcfaf0c178c422e00706eb04daea88d21a7fe9429 (diff)
downloadpandoc-d829c4820adbe7a7634f1c1d825d0d206512e6e7.tar.gz
Merged changes from branches/wrappers since r177.
Summary of main changes: + Added -o/--output and -d/--debug options to pandoc. + Modified pandoc to behave differently depending on the name of the program. For example, if the program name is 'html2latex', the default reader will be html and the default writer latex. + Removed most of the old wrappers, replacing them with symlinks to pandoc. + Rewrote markdown2pdf and created a new wrapper web2markdown, with the functionality of the old html2markdown script. These new scripts exploit pandoc's -d option to avoid having to do complex command-line parsing. + Revised man pages and documentation appropriately. git-svn-id: https://pandoc.googlecode.com/svn/trunk@279 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/wrappers/markdown2pdf.in')
-rw-r--r--src/wrappers/markdown2pdf.in68
1 files changed, 29 insertions, 39 deletions
diff --git a/src/wrappers/markdown2pdf.in b/src/wrappers/markdown2pdf.in
index 838767224..c222c1cbd 100644
--- a/src/wrappers/markdown2pdf.in
+++ b/src/wrappers/markdown2pdf.in
@@ -1,64 +1,54 @@
#!/bin/sh -e
-# converts markdown to latex, then uses latex to make a PDF
-REQUIRED=pdflatex
+REQUIRED="markdown2latex pdflatex"
### common.sh
-outfile=
-while getopts o:h opt; do
- case $opt in
- o) outfile="$OPTARG" ;;
- h|?) usage "[-o output_file] [-h] [input_file]..."; exit 2 ;;
- esac
-done
-
-shift $(($OPTIND - 1))
-
-### postopts.sh
+### tempdir.sh
-### checkin.sh
+texname=output
+logfile=$THIS_TEMPDIR/log
-if [ -z "$outfile" ]; then
- if [ -n "$1" ]; then
- outfile="${1%.*}"
- else
- outfile="stdin" # input is STDIN, since no argument given
- fi
+if ! markdown2latex -s -d "$@" >$THIS_TEMPDIR/$texname.tex 2>$logfile; then
+ [ -f $logfile ] && sed -e 's/markdown2latex/markdown2pdf/g' \
+ -e '/^INPUT=/d' -e '/^OUTPUT=/d' $logfile >&2
+ exit 1
fi
-case "$outfile" in
-*.*) ;; # skip appending extension if one is already present
-*) outfile="${outfile%.*}.pdf";;
-esac
-### tempdir.sh
-
-# We should use a filename without white spaces for pdflatex.
-TEXNAME=$THIS
+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}"
-to_utf8 "$@" | runpandoc -w latex -s >$THIS_TEMPDIR/$TEXNAME.tex
(
cd $THIS_TEMPDIR
- if ! pdflatex -interaction=batchmode $TEXNAME.tex >/dev/null 2>&1; then
+ if ! pdflatex -interaction=batchmode $texname.tex >/dev/null 2>&1; then
err "LaTeX errors:"
- from_utf8 $TEXNAME.log | sed -ne '/^!/,/^ *$/p' >&2
- if grep -q "File \`ucs.sty' not found" $TEXNAME.log; then
- err "Please install the 'unicode' package from ctan.org."
+ sed -ne '/^!/,/^ *$/p' $texname.log >&2
+ if grep -q "File \`ucs.sty' not found" $texname.log; then
+ err "Please install the 'unicode' package from CTAN:"
+ err "http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/"
+ fi
+ if grep -q "File \`fancyvrb.sty' not found" $texname.log; then
+ err "Please install the 'fancyvrb' package from CTAN:"
+ err "http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/"
fi
exit 1
fi
-)
+) || exit $?
is_target_exists=
-if [ -f "$outfile" ]; then
+if [ -f "$destname" ]; then
is_target_exists=1
- mv -f "$outfile" "$outfile~"
+ mv "$destname" "$destname~"
fi
-mv -f $THIS_TEMPDIR/$TEXNAME.pdf "$outfile"
+mv -f $THIS_TEMPDIR/$texname.pdf "$destname"
-errn "Created '$outfile'"
+errn "Created $destname"
[ -z "$is_target_exists" ] || {
- errn " (previous file has been backed up as '$outfile~')"
+ errn " (previous file has been backed up as $destname~)"
}
err .