git.iko.soy/typeable/pandoc
on master help sign in
Add "-o | --output" option to markdown2pdf, update man file.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@18 788f1e2b-df1e-0410-8736-df70ead52e1b

commitb7784aa4115bb93d7f513c79ed029a5a41f3b4d5 authorroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b> dateFri 27 Oct 2006, 11:43 (20 years ago) parentefb2dbc
2 files changed+54−16
man/man1/markdown2pdf.1+4−4 markdown2pdf+50−12
man/man1/markdown2pdf.1+4−4
@@ -2,14 +2,14 @@
22.SH NAME
33markdown2pdf \- converts markdown-formatted text to PDF, using pdflatex
44.SH SYNOPSIS
5−.B markdown2pdf [input-file]
5+.B markdown2pdf [-o|--output output-file] [input-file]
66.SH DESCRIPTION
77.B markdown2pdf
88converts input-file (or text from STDIN) from markdown-formatted
99plain text to PDF, using pdflatex. The name of the output file is derived
10−from the input file; thus, for example, if the input file is 'hello.txt',
11−the output file will be 'hello.pdf'. If the input is read from STDIN, the
12−output file will be named 'stdin.pdf'.
10+from the input file, if it is not specified; thus, for example, if the input
11+file is 'hello.txt', the output file will be 'hello.pdf'. If the input is
12+read from STDIN, the output file will be named 'stdin.pdf'.
1313.SH AUTHOR
1414John MacFarlane <jgm at berkeley.edu>
1515.SH "SEE ALSO"
markdown2pdf+50−12
@@ -1,4 +1,4 @@
1−#!/bin/sh -e
1+#!/bin/sh
22# converts markdown to latex, then uses latex to make a PDF
33
44[ -n "$(which pandoc)" ] || {
@@ -10,17 +10,55 @@
1010 exit 1
1111}
1212
13−TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
14−trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
13+outfile=
14+for option; do
15+ if [ -n "$prev" ]; then
16+ eval "$prev=\$option"
17+ prev=
18+ shift
19+ continue
20+ fi
21+ optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')
22+ case $option in
23+ -h | --h | --help )
24+ help=yes
25+ shift ;;
26+ -o | --o | --output )
27+ prev=outfile
28+ shift ;;
29+ -o=* | --o=* | --output=* )
30+ outfile=$optarg
31+ shift ;;
32+ -* ) echo >&2 "$0: unknown option: $option; aborting"
33+ exit 1 ;;
34+ * ) break ;;
35+ esac
36+done
1537
16−if [ -z "$1" ]; then
17− BASE='stdin' # input is STDIN, since no argument given
18−else
19− filename=${1##*/}
20− BASE=${filename%\.*}
38+if [ "$help" = "yes" ]; then
39+ echo "Usage: $0 [-o|--output output-file] [input-file]"
40+ exit 0
41+fi
42+
43+infile=$1
44+if [ -z "$outfile" ]; then
45+ if [ -n "$infile" ]; then
46+ outfile=${infile%.*}.pdf
47+ else
48+ outfile='stdin.pdf' # input is STDIN, since no argument given
49+ fi
2150fi
2251
23−mkdir -p $TEMP && iconv -t utf-8 $* | pandoc -w latex -s > $TEMP/$BASE.tex
52+BASE=${outfile##*/}
53+BASE=${BASE%.*}
54+
55+set -e
56+
57+TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
58+trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
59+mkdir -p $TEMP
60+
61+iconv -t utf-8 $infile | pandoc -w latex -s > $TEMP/$BASE.tex
2462(
2563 cd $TEMP
2664 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
@@ -35,10 +73,10 @@ if [ -f $BASE.pdf ]; then
3573 is_target_exists=1
3674fi
3775
38−cp --suffix=~ --backup $TEMP/$BASE.pdf .
76+mv --suffix=~ --backup $TEMP/$BASE.pdf $outfile
3977
40−echo -n >&2 "Created $BASE.pdf"
78+echo -n >&2 "Created $outfile"
4179[ -z "$is_target_exists" ] || {
42− echo -n >&2 " (previous file has been backed up as '$BASE.pdf~')"
80+ echo -n >&2 " (previous file has been backed up as '$outfile~')"
4381}
4482echo >&2 .