Add "-o | --output" option to markdown2pdf, update man file.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@18 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
roktas 2006-10-27 11:43:14 +00:00
parent efb2dbc990
commit b7784aa411
2 changed files with 54 additions and 16 deletions

View file

@ -2,14 +2,14 @@
.SH NAME
markdown2pdf \- converts markdown-formatted text to PDF, using pdflatex
.SH SYNOPSIS
.B markdown2pdf [input-file]
.B markdown2pdf [-o|--output output-file] [input-file]
.SH DESCRIPTION
.B markdown2pdf
converts input-file (or text from STDIN) from markdown-formatted
plain text to PDF, using pdflatex. The name of the output file is derived
from the input file; thus, for example, if the input file is 'hello.txt',
the output file will be 'hello.pdf'. If the input is read from STDIN, the
output file will be named 'stdin.pdf'.
from the input file, if it is not specified; thus, for example, if the input
file is 'hello.txt', the output file will be 'hello.pdf'. If the input is
read from STDIN, the output file will be named 'stdin.pdf'.
.SH AUTHOR
John MacFarlane <jgm at berkeley.edu>
.SH "SEE ALSO"

View file

@ -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
mkdir -p $TEMP && iconv -t utf-8 $* | pandoc -w latex -s > $TEMP/$BASE.tex
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
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 .