git.iko.soy/typeable/pandoc
on master help sign in
Modified shell scripts to use new Pandoc --dump-args and
58697ebfiddlosopher
src/wrappers/common.sh+16
@@ -6,6 +6,11 @@ NEWLINE='
6err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
6err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
7errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
7errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
8
8
9+usage () {
10+ err "$1 - $2" # short description
11+ err "See the $1(1) man page for usage."
12+}
13+
9# Portable which(1).
14# Portable which(1).
10pathfind () {
15pathfind () {
11 oldifs="$IFS"; IFS=':'
16 oldifs="$IFS"; IFS=':'
@@ -25,3 +30,14 @@ for p in pandoc $REQUIRED; do
25 exit 1
30 exit 1
26 }
31 }
27done
32done
33+
34+CONF=$(pandoc --dump-args "$@" 2>&1) || {
35+ errcode=$?
36+ echo "$CONF" | sed -e '/^pandoc \[OPTIONS\] \[FILES\]/,$d' >&2
37+ [ $errcode -eq 2 ] && usage "$THIS" "$SYNOPSIS"
38+ exit $errcode
39+}
40+
41+OUTPUT=$(echo "$CONF" | sed -ne '1p')
42+ARGS=$(echo "$CONF" | sed -e '1d')
43+
src/wrappers/html2markdown.in+37−53
@@ -3,6 +3,7 @@
3# uses an available program to fetch URL and tidy to normalize it first
3# uses an available program to fetch URL and tidy to normalize it first
4
4
5REQUIRED="tidy"
5REQUIRED="tidy"
6+SYNOPSIS="converts HTML from a URL, file, or STDIN to markdown-formatted text."
6
7
7### common.sh
8### common.sh
8
9
@@ -59,63 +60,46 @@ grab_url_with () {
59 $prog "$@" "$url"
60 $prog "$@" "$url"
60}
61}
61
62
62−add_option () {
63− options="$options$NEWLINE$1"
64−}
65−
66−options=
67argument=
63argument=
68encoding=
64encoding=
69grabber=
65grabber=
70
66
71# Parse command-line arguments
67# Parse command-line arguments
68+parse_arguments () {
72−while [ $# -gt 0 ]; do
69+ while [ $# -gt 0 ]; do
73− case "$1" in
70+ case "$1" in
74− -h|--help)
75− pandoc -h 2>&1 | sed -e 's/pandoc/html2markdown/' \
76− -e '/^[[:space:]]*\(-f\|-t\|-S\|-N\|-m\|-i\|-c\|-T\|-D\|-d\)/,/./d'\
77− 1>&2
78− err " -e ENCODING, --encoding=ENCODING"
79− err " Specify character encoding of input"
80− err " -g COMMAND, --grabber=COMMAND"
81− err " Specify command to be used to grab contents of URL"
82− exit 0 ;;
83− -v|--version)
84− pandoc -v 2>&1 | sed -e 's/pandoc/html2markdown/' 1>&2
85− exit 0 ;;
86− -e)
87− shift
88− encoding=$1 ;;
89− --encoding=*)
71+ --encoding=*)
90− wholeopt=$1
72+ wholeopt="$1"
91− # extract encoding from after =
73+ # extract encoding from after =
92− encoding=${wholeopt#*=} ;;
74+ encoding="${wholeopt#*=}" ;;
93− -g)
75+ -e|--encoding|-encoding)
94− shift
76+ shift
95− grabber=$1 ;;
77+ encoding="$1" ;;
96− --grabber=*)
78+ --grabber=*)
97− wholeopt=$1
79+ wholeopt="$1"
98− # extract encoding from after =
80+ # extract encoding from after =
99− grabber=${wholeopt#*=} ;;
81+ grabber="\"${wholeopt#*=}\"" ;;
100− -o|--output|-b|--tab-stop|-H|--include-in-header| \
82+ -g|--grabber|-grabber)
101− -A|--include-after-body|-C|-B|--include-before-body| \
102− -C|--custom-header|-T|--title-prefix)
103− add_option $1
104− shift
83+ shift
105− add_option $1 ;;
84+ grabber="$1" ;;
106− -*) add_option $1 ;;
107− *)
85+ *)
108− if [ -z "$argument" ]; then
86+ if [ -z "$argument" ]; then
109− argument=$1
87+ argument="$1"
110− else
88+ else
111− err "Warning: extra argument '$1' will be ignored."
89+ err "Warning: extra argument '$1' will be ignored."
112− fi ;;
90+ fi ;;
113− esac
91+ esac
114− shift
92+ shift
115−done
93+ done
94+ export encoding
95+ export grabber
96+ export argument
97+}
116
98
117−# Unpack options. Now "$@" will hold the pandoc options.
99+oldifs="$IFS"
118−oldifs="$IFS"; IFS="$NEWLINE"; set -- $options; IFS="$oldifs"
100+IFS=$NEWLINE
101+parse_arguments $ARGS
102+IFS="$oldifs"
119
103
120inurl=
104inurl=
121if [ -n "$argument" ] && ! [ -f "$argument" ]; then
105if [ -n "$argument" ] && ! [ -f "$argument" ]; then
@@ -164,11 +148,11 @@ else # assume UTF-8
164fi
148fi
165
149
166if [ -z "$argument" ]; then
150if [ -z "$argument" ]; then
167− tidy -utf8 2>/dev/null | pandoc -r html -w markdown "$@"
151+ tidy -utf8 2>/dev/null | pandoc --ignore-args -r html -w markdown "$@"
168else
152else
169 if [ -f "$argument" ]; then
153 if [ -f "$argument" ]; then
170 to_utf8 "$argument" |
154 to_utf8 "$argument" |
171− tidy -utf8 2>/dev/null | pandoc -r html -w markdown "$@"
155+ tidy -utf8 2>/dev/null | pandoc --ignore-args -r html -w markdown "$@"
172 else
156 else
173 err "File '$argument' not found."
157 err "File '$argument' not found."
174 exit 1
158 exit 1
src/wrappers/markdown2pdf.in+17−18
@@ -1,6 +1,7 @@
1#!/bin/sh -e
1#!/bin/sh -e
2
2
3REQUIRED="pdflatex"
3REQUIRED="pdflatex"
4+SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
4
5
5### common.sh
6### common.sh
6
7
@@ -8,27 +9,25 @@ REQUIRED="pdflatex"
8
9
9texname=output
10texname=output
10logfile=$THIS_TEMPDIR/log
11logfile=$THIS_TEMPDIR/log
12+origdir=$(pwd)
11
13
12−if ! pandoc -s -d -r markdown -w latex "$@" >$THIS_TEMPDIR/$texname.tex \
14+pandoc -s -r markdown -w latex "$@" -o - >$THIS_TEMPDIR/$texname.tex \
13−2>$logfile; then
15+2>$logfile
14− [ -f $logfile ] && sed -e 's/^pandoc/markdown2pdf/g' \
15− -e '/^INPUT=/d' -e '/^OUTPUT=/d' \
16− -e '/^[[:space:]]*\(-f\|-t\|-s\|-R\|-S\|-m\|-i\|-c\|-T\|-D\|-d\)/,/./d'\
17− -e 's/(implies -s)//g' $logfile >&2
18− exit 1
19−fi
20
16
21−outfile="$(sed -ne 's/^OUTPUT=//p' $logfile)"
17+if [ "$OUTPUT" = "-" ]; then
22−IFS="$NEWLINE"
18+ firstinfile="$(echo $ARGS | sed -ne '1p')"
23−set -- $(sed -ne 's/^INPUT=//p' $logfile)
24−firstinfilebase="${1%.*}"
19+ firstinfilebase="${firstinfile%.*}"
25−defaultdest="${firstinfilebase:-stdin}.pdf"
20+ destname="${firstinfilebase:-stdin}.pdf"
21+else
26−destname="${outfile:-$defaultdest}"
22+ destname="$OUTPUT"
23+fi
27
24
28(
25(
29 cd $THIS_TEMPDIR
26 cd $THIS_TEMPDIR
30− if ! pdflatex -interaction=batchmode $texname.tex >/dev/null 2>&1; then
27+ TEXINPUTS=$TEXINPUTS:$origdir pdflatex -interaction=batchmode \
28+ $texname.tex >/dev/null 2>&1 || {
29+ errorcode=$?
31− err "${THIS}: pdfLaTeX error context:"
30+ err "${THIS}: pdfLaTeX error context:"
32 sed -ne '/^!/,/^[[:space:]]*$/p' \
31 sed -ne '/^!/,/^[[:space:]]*$/p' \
33 -ne '/^[Ll]a[Tt]e[Xx] [Ww]arning/,/^[[:space:]]*$/p' \
32 -ne '/^[Ll]a[Tt]e[Xx] [Ww]arning/,/^[[:space:]]*$/p' \
34 -ne '/^[Ee]rror/,/^[[:space:]]*$/p' $texname.log >&2
33 -ne '/^[Ee]rror/,/^[[:space:]]*$/p' $texname.log >&2
@@ -40,8 +39,8 @@ destname="${outfile:-$defaultdest}"
40 err "${THIS}: Please install the 'fancyvrb' package from CTAN:"
39 err "${THIS}: Please install the 'fancyvrb' package from CTAN:"
41 err " http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/"
40 err " http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/"
42 fi
41 fi
43− exit 1
42+ exit $errorcode
44− fi
43+ }
45) || exit $?
44) || exit $?
46
45
47is_target_exists=
46is_target_exists=