git.iko.soy/typeable/pandoc
on master help sign in
Replace which(1) in all wrappers with 'pathfind', a POSIX-compliant shell
2763382roktas
html2markdown+18−5
@@ -2,11 +2,24 @@
2# converts html to markdown
2# converts html to markdown
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
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+
5for p in pandoc tidy; do
18for p in pandoc tidy; do
6− which $p >/dev/null 2>&1 || {
19+ pathfind $p || {
7− echo >&2 "You need '$p' to use this program!"
20+ echo >&2 "You need '$p' to use this program!"
8− exit 1
21+ exit 1
9− }
22+ }
10done
23done
11
24
12if [ -z "$1" ] || [ -f $1 ]; then
25if [ -z "$1" ] || [ -f $1 ]; then
@@ -17,7 +30,7 @@ else
17 # Treat given argument as an URL. Locate a
30 # Treat given argument as an URL. Locate a
18 # sensible text based browser (note the order).
31 # sensible text based browser (note the order).
19 for p in wget lynx w3m curl links w3c; do
32 for p in wget lynx w3m curl links w3c; do
20− if which $p >/dev/null 2>&1; then
33+ if pathfind $p; then
21 DUMPER=$p
34 DUMPER=$p
22 break
35 break
23 fi
36 fi
latex2markdown+17−4
@@ -1,11 +1,24 @@
1#!/bin/sh -e
1#!/bin/sh -e
2# runs pandoc to convert latex to markdown
2# runs pandoc to convert latex to markdown
3
3
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+
4for p in pandoc; do
17for p in pandoc; do
5− which $p >/dev/null 2>&1 || {
18+ pathfind $p || {
6− echo >&2 "You need '$p' to use this program!"
19+ echo >&2 "You need '$p' to use this program!"
7− exit 1
20+ exit 1
8− }
21+ }
9done
22done
10
23
11iconv -t utf-8 $* | pandoc $PANDOC_OPTS -r latex -w markdown -s | iconv -f utf-8
24iconv -t utf-8 $* | pandoc $PANDOC_OPTS -r latex -w markdown -s | iconv -f utf-8
markdown2html+17−4
@@ -1,11 +1,24 @@
1#!/bin/sh -e
1#!/bin/sh -e
2# converts markdown to HTML
2# converts markdown to HTML
3
3
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+
4for p in pandoc; do
17for p in pandoc; do
5− which $p >/dev/null 2>&1 || {
18+ pathfind $p || {
6− echo >&2 "You need '$p' to use this program!"
19+ echo >&2 "You need '$p' to use this program!"
7− exit 1
20+ exit 1
8− }
21+ }
9done
22done
10
23
11iconv -t utf-8 $* | pandoc $PANDOC_OPTS | iconv -f utf-8
24iconv -t utf-8 $* | pandoc $PANDOC_OPTS | iconv -f utf-8
markdown2latex+17−4
@@ -1,11 +1,24 @@
1#!/bin/sh -e
1#!/bin/sh -e
2# converts markdown to latex
2# converts markdown to latex
3
3
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+
4for p in pandoc; do
17for p in pandoc; do
5− which $p >/dev/null 2>&1 || {
18+ pathfind $p || {
6− echo >&2 "You need '$p' to use this program!"
19+ echo >&2 "You need '$p' to use this program!"
7− exit 1
20+ exit 1
8− }
21+ }
9done
22done
10
23
11iconv -t utf-8 $* | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8
24iconv -t utf-8 $* | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8
markdown2pdf+33−20
@@ -1,34 +1,47 @@
1#!/bin/sh
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+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+
4for p in pandoc pdflatex; do
17for p in pandoc pdflatex; do
5− which $p >/dev/null 2>&1 || {
18+ pathfind $p || {
6− echo >&2 "You need '$p' to use this program!"
19+ echo >&2 "You need '$p' to use this program!"
7− exit 1
20+ exit 1
8− }
21+ }
9done
22done
10
23
11outfile=
24outfile=
12for option; do
25for option; do
13 if [ -n "$prev" ]; then
26 if [ -n "$prev" ]; then
14− eval "$prev=\$option"
27+ eval "$prev=\$option"
15− prev=
28+ prev=
16− shift
29+ shift
17− continue
30+ continue
18 fi
31 fi
19 optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')
32 optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')
20 case $option in
33 case $option in
21 -h | --h | --help )
34 -h | --h | --help )
22− help=1
35+ help=1
23− shift ;;
36+ shift ;;
24 -o | --o | --output )
37 -o | --o | --output )
25− prev=outfile
38+ prev=outfile
26− shift ;;
39+ shift ;;
27 -o=* | --o=* | --output=* )
40 -o=* | --o=* | --output=* )
28− outfile=$optarg
41+ outfile=$optarg
29− shift ;;
42+ shift ;;
30 -* ) echo >&2 "$0: unknown option: $option; aborting"
43 -* ) echo >&2 "$0: unknown option: $option; aborting"
31− exit 1 ;;
44+ exit 1 ;;
32 * ) break ;;
45 * ) break ;;
33 esac
46 esac
34done
47done
@@ -41,9 +54,9 @@ done
41infile=$1
54infile=$1
42if [ -z "$outfile" ]; then
55if [ -z "$outfile" ]; then
43 if [ -n "$infile" ]; then
56 if [ -n "$infile" ]; then
44− outfile=${infile%.*}.pdf
57+ outfile=${infile%.*}.pdf
45 else
58 else
46− outfile='stdin.pdf' # input is STDIN, since no argument given
59+ outfile='stdin.pdf' # input is STDIN, since no argument given
47 fi
60 fi
48fi
61fi
49
62
@@ -61,9 +74,9 @@ pandoc $PANDOC_OPTS -w latex -s | \
61iconv -f utf-8 > $TEMP/$BASE.tex && (
74iconv -f utf-8 > $TEMP/$BASE.tex && (
62 cd $TEMP
75 cd $TEMP
63 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
76 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
64− echo >&2 "LaTeX errors:"
77+ echo >&2 "LaTeX errors:"
65− cat >&2 $BASE.log
78+ cat >&2 $BASE.log
66− exit 1
79+ exit 1
67 fi
80 fi
68) || exit $?
81) || exit $?
69
82