git.iko.soy/typeable/pandoc
on master help sign in
Portability fixes and various cleanups in wrapper scripts:

+ Fix the tests at the header of wrappers. which(1) doesn't behave as expected on some systems. We should only assume that it's pretty widely available (for example, it's a builtin in csh) and we should only rely on its exit code by ignoring its output. + Replace 'echo -n' with 'printf' as the latter is recommended. + In markdown2pdf script, '--suffix' and '--backup' options of mv(1) appear to be GNU-ism. Apply a workaround. + Wrap some long lines to fit in an 80-column screen. + Remove spaces at the line ends. git-svn-id: https://pandoc.googlecode.com/svn/trunk@92 788f1e2b-df1e-0410-8736-df70ead52e1b

commit3ed8fc8784496722af85b6ec2ff5120c75db84dc authorroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 12 Nov 2006, 12:11 (20 years ago) parent69e23af
5 files changed+55−40
html2markdown+17−14 latex2markdown+8−4 markdown2html+9−5 markdown2latex+8−4 markdown2pdf+13−13
html2markdown+17−14
@@ -2,22 +2,22 @@
22# converts html to markdown
33# uses an available program to fetch URL and tidy to normalize it first
44
5−[ -n "$(which pandoc)" ] || {
6− echo >&2 "You need 'pandoc' to use this program!"
7− exit 1
8−}
9−[ -n "$(which tidy)" ] || {
10− echo >&2 "You need 'tidy' to use this program!"
11− exit 1
12−}
5+for 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+ }
10+done
1311
14−if [ -z "$1" ] || [ -f $1 ]; then
15− tidy -utf8 $1 2>/dev/null | pandoc $PANDOC_OPTS -r html -w markdown -s | iconv -f utf-8
12+if [ -z "$1" ] || [ -f $1 ]; then
13+ tidy -utf8 $1 2>/dev/null | \
14+ pandoc $PANDOC_OPTS -r html -w markdown -s | \
15+ iconv -f utf-8
1616else
1717 # Treat given argument as an URL. Locate a
1818 # sensible text based browser (note the order).
1919 for p in wget lynx w3m curl links w3c; do
20− if which $p >/dev/null; then
20+ if which $p >/dev/null 2>&1; then
2121 DUMPER=$p
2222 break
2323 fi
@@ -30,10 +30,13 @@ else
3030 curl) OPT="" ;;
3131 links) OPT="-source" ;;
3232 w3c) OPT="-n -get" ;;
33− "") echo -n >&2 "Needs a program to fetch the URL "
34− echo -n >&2 "(e.g. wget, w3m, lynx, w3c, or curl)."
33+ "") printf "Needs a program to fetch the URL " >&2
34+ printf "(e.g. wget, w3m, lynx, w3c, or curl)." >&2
3535 exit 1 ;;
3636 esac
3737 # Fetch and feed to pandoc.
38− $DUMPER $OPT $1 2>/dev/null | tidy -utf8 2>/dev/null | pandoc $PANDOC_OPTS -r html -w markdown -s | iconv -f utf-8
38+ $DUMPER $OPT $1 2>/dev/null | \
39+ tidy -utf8 2>/dev/null | \
40+ pandoc $PANDOC_OPTS -r html -w markdown -s | \
41+ iconv -f utf-8
3942fi
latex2markdown+8−4
@@ -1,7 +1,11 @@
11#!/bin/sh -e
22# runs pandoc to convert latex to markdown
3−[ -n "$(which pandoc)" ] || {
4− echo >&2 "You need 'pandoc' to use this program!"
5− exit 1
6−}
3+
4+for 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+ }
9+done
10+
711iconv -t utf-8 $* | pandoc $PANDOC_OPTS -r latex -w markdown -s | iconv -f utf-8
markdown2html+9−5
@@ -1,7 +1,11 @@
11#!/bin/sh -e
2−# converts markdown to HTML
3−[ -n "$(which pandoc)" ] || {
4− echo >&2 "You need 'pandoc' to use this program!"
5− exit 1
6−}
2+# converts markdown to HTML
3+
4+for 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+ }
9+done
10+
711iconv -t utf-8 $* | pandoc $PANDOC_OPTS | iconv -f utf-8
markdown2latex+8−4
@@ -1,7 +1,11 @@
11#!/bin/sh -e
22# converts markdown to latex
3−[ -n "$(which pandoc)" ] || {
4− echo >&2 "You need 'pandoc' to use this program!"
5− exit 1
6−}
3+
4+for 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+ }
9+done
10+
711iconv -t utf-8 $* | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8
markdown2pdf+13−13
@@ -1,14 +1,12 @@
11#!/bin/sh
22# converts markdown to latex, then uses latex to make a PDF
33
4−[ -n "$(which pandoc)" ] || {
5− echo >&2 "You need 'pandoc' to use this program!"
6− exit 1
7−}
8−[ -n "$(which pdflatex)" ] || {
9− echo >&2 "You need 'pdflatex' to use this program!"
10− exit 1
11−}
4+for 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+ }
9+done
1210
1311outfile=
1412for option; do
@@ -58,8 +56,9 @@ TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
5856trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
5957mkdir -p $TEMP
6058
61−iconv -t utf-8 $infile | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8 > $TEMP/$BASE.tex
62−(
59+iconv -t utf-8 $infile | \
60+pandoc $PANDOC_OPTS -w latex -s | \
61+iconv -f utf-8 > $TEMP/$BASE.tex && (
6362 cd $TEMP
6463 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
6564 echo >&2 "LaTeX errors:"
@@ -71,12 +70,13 @@ iconv -t utf-8 $infile | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8 > $TEM
7170is_target_exists=
7271if [ -f $outfile ]; then
7372 is_target_exists=1
73+ mv -f $outfile $outfile~
7474fi
7575
76−mv --suffix=~ --backup $TEMP/$BASE.pdf $outfile
76+mv -f $TEMP/$BASE.pdf $outfile
7777
78−echo -n >&2 "Created $outfile"
78+printf "Created $outfile" >&2
7979[ -z "$is_target_exists" ] || {
80− echo -n >&2 " (previous file has been backed up as '$outfile~')"
80+ printf " (previous file has been backed up as '$outfile~')" >&2
8181}
8282echo >&2 .