aboutsummaryrefslogtreecommitdiff
path: root/markdown2pdf
diff options
context:
space:
mode:
authorroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-10-27 11:43:14 +0000
committerroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-10-27 11:43:14 +0000
commitb7784aa4115bb93d7f513c79ed029a5a41f3b4d5 (patch)
tree5ca2e65ac45bc280227f0feb6593f8052f4ab6d8 /markdown2pdf
parentefb2dbc9901ccf85991709e6b797760efb3f0c6b (diff)
downloadpandoc-b7784aa4115bb93d7f513c79ed029a5a41f3b4d5.tar.gz
Add "-o | --output" option to markdown2pdf, update man file.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@18 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'markdown2pdf')
-rw-r--r--markdown2pdf62
1 files changed, 50 insertions, 12 deletions
diff --git a/markdown2pdf b/markdown2pdf
index 6a76aab7d..bea336a07 100644
--- a/markdown2pdf
+++ b/markdown2pdf
@@ -1,4 +1,4 @@
-#!/bin/sh -e
+#!/bin/sh
# converts markdown to latex, then uses latex to make a PDF
[ -n "$(which pandoc)" ] || {
@@ -10,17 +10,55 @@
exit 1
}
-TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
-trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
+outfile=
+for option; do
+ if [ -n "$prev" ]; then
+ eval "$prev=\$option"
+ prev=
+ shift
+ continue
+ fi
+ optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')
+ case $option in
+ -h | --h | --help )
+ help=yes
+ shift ;;
+ -o | --o | --output )
+ prev=outfile
+ shift ;;
+ -o=* | --o=* | --output=* )
+ outfile=$optarg
+ shift ;;
+ -* ) echo >&2 "$0: unknown option: $option; aborting"
+ exit 1 ;;
+ * ) break ;;
+ esac
+done
-if [ -z "$1" ]; then
- BASE='stdin' # input is STDIN, since no argument given
-else
- filename=${1##*/}
- BASE=${filename%\.*}
+if [ "$help" = "yes" ]; then
+ echo "Usage: $0 [-o|--output output-file] [input-file]"
+ exit 0
+fi
+
+infile=$1
+if [ -z "$outfile" ]; then
+ if [ -n "$infile" ]; then
+ outfile=${infile%.*}.pdf
+ else
+ outfile='stdin.pdf' # input is STDIN, since no argument given
+ fi
fi
-mkdir -p $TEMP && iconv -t utf-8 $* | pandoc -w latex -s > $TEMP/$BASE.tex
+BASE=${outfile##*/}
+BASE=${BASE%.*}
+
+set -e
+
+TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
+trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
+mkdir -p $TEMP
+
+iconv -t utf-8 $infile | pandoc -w latex -s > $TEMP/$BASE.tex
(
cd $TEMP
if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
@@ -35,10 +73,10 @@ if [ -f $BASE.pdf ]; then
is_target_exists=1
fi
-cp --suffix=~ --backup $TEMP/$BASE.pdf .
+mv --suffix=~ --backup $TEMP/$BASE.pdf $outfile
-echo -n >&2 "Created $BASE.pdf"
+echo -n >&2 "Created $outfile"
[ -z "$is_target_exists" ] || {
- echo -n >&2 " (previous file has been backed up as '$BASE.pdf~')"
+ echo -n >&2 " (previous file has been backed up as '$outfile~')"
}
echo >&2 .