git.iko.soy/typeable/pandoc
on master help sign in
Replace which(1) in all wrappers with 'pathfind', a POSIX-compliant shell

function. Expand tabs to four spaces. git-svn-id: https://pandoc.googlecode.com/svn/trunk@94 788f1e2b-df1e-0410-8736-df70ead52e1b

commit2763382dd803916e34e6575904147d7e3594a7f6 authorroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 12 Nov 2006, 21:17 (20 years ago) parent8e5f3e6
5 files changed+102−37
html2markdown+18−5 latex2markdown+17−4 markdown2html+17−4 markdown2latex+17−4 markdown2pdf+33−20
html2markdown+18−5
@@ -2,11 +2,24 @@
22# converts html to markdown
33# uses an available program to fetch URL and tidy to normalize it first
44
5+pathfind () { # portable which(1), code taken from Debian Developer's Reference
6+ OLDIFS="$IFS"
7+ IFS=:
8+ for _p in $PATH; do
9+ if [ -x "$_p/$*" ]; then
10+ IFS="$OLDIFS"
11+ return 0
12+ fi
13+ done
14+ IFS="$OLDIFS"
15+ return 1
16+}
17+
518for p in pandoc tidy; do
6− which $p >/dev/null 2>&1 || {
7− echo >&2 "You need '$p' to use this program!"
8− exit 1
9− }
19+ pathfind $p || {
20+ echo >&2 "You need '$p' to use this program!"
21+ exit 1
22+ }
1023done
1124
1225if [ -z "$1" ] || [ -f $1 ]; then
@@ -17,7 +30,7 @@ else
1730 # Treat given argument as an URL. Locate a
1831 # sensible text based browser (note the order).
1932 for p in wget lynx w3m curl links w3c; do
20− if which $p >/dev/null 2>&1; then
33+ if pathfind $p; then
2134 DUMPER=$p
2235 break
2336 fi
latex2markdown+17−4
@@ -1,11 +1,24 @@
11#!/bin/sh -e
22# runs pandoc to convert latex to markdown
33
4+pathfind () { # portable which(1), code taken from Debian Developer's Reference
5+ OLDIFS="$IFS"
6+ IFS=:
7+ for _p in $PATH; do
8+ if [ -x "$_p/$*" ]; then
9+ IFS="$OLDIFS"
10+ return 0
11+ fi
12+ done
13+ IFS="$OLDIFS"
14+ return 1
15+}
16+
417for p in pandoc; do
5− which $p >/dev/null 2>&1 || {
6− echo >&2 "You need '$p' to use this program!"
7− exit 1
8− }
18+ pathfind $p || {
19+ echo >&2 "You need '$p' to use this program!"
20+ exit 1
21+ }
922done
1023
1124iconv -t utf-8 $* | pandoc $PANDOC_OPTS -r latex -w markdown -s | iconv -f utf-8
markdown2html+17−4
@@ -1,11 +1,24 @@
11#!/bin/sh -e
22# converts markdown to HTML
33
4+pathfind () { # portable which(1), code taken from Debian Developer's Reference
5+ OLDIFS="$IFS"
6+ IFS=:
7+ for _p in $PATH; do
8+ if [ -x "$_p/$*" ]; then
9+ IFS="$OLDIFS"
10+ return 0
11+ fi
12+ done
13+ IFS="$OLDIFS"
14+ return 1
15+}
16+
417for p in pandoc; do
5− which $p >/dev/null 2>&1 || {
6− echo >&2 "You need '$p' to use this program!"
7− exit 1
8− }
18+ pathfind $p || {
19+ echo >&2 "You need '$p' to use this program!"
20+ exit 1
21+ }
922done
1023
1124iconv -t utf-8 $* | pandoc $PANDOC_OPTS | iconv -f utf-8
markdown2latex+17−4
@@ -1,11 +1,24 @@
11#!/bin/sh -e
22# converts markdown to latex
33
4+pathfind () { # portable which(1), code taken from Debian Developer's Reference
5+ OLDIFS="$IFS"
6+ IFS=:
7+ for _p in $PATH; do
8+ if [ -x "$_p/$*" ]; then
9+ IFS="$OLDIFS"
10+ return 0
11+ fi
12+ done
13+ IFS="$OLDIFS"
14+ return 1
15+}
16+
417for p in pandoc; do
5− which $p >/dev/null 2>&1 || {
6− echo >&2 "You need '$p' to use this program!"
7− exit 1
8− }
18+ pathfind $p || {
19+ echo >&2 "You need '$p' to use this program!"
20+ exit 1
21+ }
922done
1023
1124iconv -t utf-8 $* | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8
markdown2pdf+33−20
@@ -1,34 +1,47 @@
11#!/bin/sh
22# converts markdown to latex, then uses latex to make a PDF
33
4+pathfind () { # portable which(1), code taken from Debian Developer's Reference
5+ OLDIFS="$IFS"
6+ IFS=:
7+ for _p in $PATH; do
8+ if [ -x "$_p/$*" ]; then
9+ IFS="$OLDIFS"
10+ return 0
11+ fi
12+ done
13+ IFS="$OLDIFS"
14+ return 1
15+}
16+
417for p in pandoc pdflatex; do
5− which $p >/dev/null 2>&1 || {
6− echo >&2 "You need '$p' to use this program!"
7− exit 1
8− }
18+ pathfind $p || {
19+ echo >&2 "You need '$p' to use this program!"
20+ exit 1
21+ }
922done
1023
1124outfile=
1225for option; do
1326 if [ -n "$prev" ]; then
14− eval "$prev=\$option"
15− prev=
16− shift
17− continue
27+ eval "$prev=\$option"
28+ prev=
29+ shift
30+ continue
1831 fi
1932 optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')
2033 case $option in
2134 -h | --h | --help )
22− help=1
23− shift ;;
35+ help=1
36+ shift ;;
2437 -o | --o | --output )
25− prev=outfile
26− shift ;;
38+ prev=outfile
39+ shift ;;
2740 -o=* | --o=* | --output=* )
28− outfile=$optarg
29− shift ;;
41+ outfile=$optarg
42+ shift ;;
3043 -* ) echo >&2 "$0: unknown option: $option; aborting"
31− exit 1 ;;
44+ exit 1 ;;
3245 * ) break ;;
3346 esac
3447done
@@ -41,9 +54,9 @@ done
4154infile=$1
4255if [ -z "$outfile" ]; then
4356 if [ -n "$infile" ]; then
44− outfile=${infile%.*}.pdf
57+ outfile=${infile%.*}.pdf
4558 else
46− outfile='stdin.pdf' # input is STDIN, since no argument given
59+ outfile='stdin.pdf' # input is STDIN, since no argument given
4760 fi
4861fi
4962
@@ -61,9 +74,9 @@ pandoc $PANDOC_OPTS -w latex -s | \
6174iconv -f utf-8 > $TEMP/$BASE.tex && (
6275 cd $TEMP
6376 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
64− echo >&2 "LaTeX errors:"
65− cat >&2 $BASE.log
66− exit 1
77+ echo >&2 "LaTeX errors:"
78+ cat >&2 $BASE.log
79+ exit 1
6780 fi
6881) || exit $?
6982