git.iko.soy/typeable/pandoc
on master help sign in
Add "-o | --output" option to markdown2pdf, update man file.
b7784aaroktas
man/man1/markdown2pdf.1+4−4
@@ -2,14 +2,14 @@
2.SH NAME
2.SH NAME
3markdown2pdf \- converts markdown-formatted text to PDF, using pdflatex
3markdown2pdf \- converts markdown-formatted text to PDF, using pdflatex
4.SH SYNOPSIS
4.SH SYNOPSIS
5−.B markdown2pdf [input-file]
5+.B markdown2pdf [-o|--output output-file] [input-file]
6.SH DESCRIPTION
6.SH DESCRIPTION
7.B markdown2pdf
7.B markdown2pdf
8converts input-file (or text from STDIN) from markdown-formatted
8converts input-file (or text from STDIN) from markdown-formatted
9plain text to PDF, using pdflatex. The name of the output file is derived
9plain 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',
10+from the input file, if it is not specified; thus, for example, if the input
11−the output file will be 'hello.pdf'. If the input is read from STDIN, the
11+file is 'hello.txt', the output file will be 'hello.pdf'. If the input is
12−output file will be named 'stdin.pdf'.
12+read from STDIN, the output file will be named 'stdin.pdf'.
13.SH AUTHOR
13.SH AUTHOR
14John MacFarlane <jgm at berkeley.edu>
14John MacFarlane <jgm at berkeley.edu>
15.SH "SEE ALSO"
15.SH "SEE ALSO"
markdown2pdf+50−12
@@ -1,4 +1,4 @@
1−#!/bin/sh -e
1+#!/bin/sh
2# converts markdown to latex, then uses latex to make a PDF
2# converts markdown to latex, then uses latex to make a PDF
3
3
4[ -n "$(which pandoc)" ] || {
4[ -n "$(which pandoc)" ] || {
@@ -10,17 +10,55 @@
10 exit 1
10 exit 1
11}
11}
12
12
13−TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
13+outfile=
14−trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
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
15
37
16−if [ -z "$1" ]; then
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
17− BASE='stdin' # input is STDIN, since no argument given
48+ outfile='stdin.pdf' # input is STDIN, since no argument given
18−else
49+ fi
19− filename=${1##*/}
20− BASE=${filename%\.*}
21fi
50fi
22
51
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+
23−mkdir -p $TEMP && iconv -t utf-8 $* | pandoc -w latex -s > $TEMP/$BASE.tex
61+iconv -t utf-8 $infile | pandoc -w latex -s > $TEMP/$BASE.tex
24(
62(
25 cd $TEMP
63 cd $TEMP
26 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
64 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
@@ -35,10 +73,10 @@ if [ -f $BASE.pdf ]; then
35 is_target_exists=1
73 is_target_exists=1
36fi
74fi
37
75
38−cp --suffix=~ --backup $TEMP/$BASE.pdf .
76+mv --suffix=~ --backup $TEMP/$BASE.pdf $outfile
39
77
40−echo -n >&2 "Created $BASE.pdf"
78+echo -n >&2 "Created $outfile"
41[ -z "$is_target_exists" ] || {
79[ -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~')"
43}
81}
44echo >&2 .
82echo >&2 .