diff options
-rw-r--r-- | html2markdown | 23 | ||||
-rw-r--r-- | latex2markdown | 21 | ||||
-rw-r--r-- | markdown2html | 21 | ||||
-rw-r--r-- | markdown2latex | 21 | ||||
-rw-r--r-- | markdown2pdf | 53 |
5 files changed, 102 insertions, 37 deletions
diff --git a/html2markdown b/html2markdown index 48232acbb..4320ce9b1 100644 --- a/html2markdown +++ b/html2markdown @@ -2,11 +2,24 @@ # converts html to markdown # uses an available program to fetch URL and tidy to normalize it first +pathfind () { # portable which(1), code taken from Debian Developer's Reference + OLDIFS="$IFS" + IFS=: + for _p in $PATH; do + if [ -x "$_p/$*" ]; then + IFS="$OLDIFS" + return 0 + fi + done + IFS="$OLDIFS" + return 1 +} + for p in pandoc tidy; do - which $p >/dev/null 2>&1 || { - echo >&2 "You need '$p' to use this program!" - exit 1 - } + pathfind $p || { + echo >&2 "You need '$p' to use this program!" + exit 1 + } done if [ -z "$1" ] || [ -f $1 ]; then @@ -17,7 +30,7 @@ else # Treat given argument as an URL. Locate a # sensible text based browser (note the order). for p in wget lynx w3m curl links w3c; do - if which $p >/dev/null 2>&1; then + if pathfind $p; then DUMPER=$p break fi diff --git a/latex2markdown b/latex2markdown index e5e276d62..4f5efef83 100644 --- a/latex2markdown +++ b/latex2markdown @@ -1,11 +1,24 @@ #!/bin/sh -e # runs pandoc to convert latex to markdown +pathfind () { # portable which(1), code taken from Debian Developer's Reference + OLDIFS="$IFS" + IFS=: + for _p in $PATH; do + if [ -x "$_p/$*" ]; then + IFS="$OLDIFS" + return 0 + fi + done + IFS="$OLDIFS" + return 1 +} + for p in pandoc; do - which $p >/dev/null 2>&1 || { - echo >&2 "You need '$p' to use this program!" - exit 1 - } + pathfind $p || { + echo >&2 "You need '$p' to use this program!" + exit 1 + } done iconv -t utf-8 $* | pandoc $PANDOC_OPTS -r latex -w markdown -s | iconv -f utf-8 diff --git a/markdown2html b/markdown2html index d71e434b4..280c1cf90 100644 --- a/markdown2html +++ b/markdown2html @@ -1,11 +1,24 @@ #!/bin/sh -e # converts markdown to HTML +pathfind () { # portable which(1), code taken from Debian Developer's Reference + OLDIFS="$IFS" + IFS=: + for _p in $PATH; do + if [ -x "$_p/$*" ]; then + IFS="$OLDIFS" + return 0 + fi + done + IFS="$OLDIFS" + return 1 +} + for p in pandoc; do - which $p >/dev/null 2>&1 || { - echo >&2 "You need '$p' to use this program!" - exit 1 - } + pathfind $p || { + echo >&2 "You need '$p' to use this program!" + exit 1 + } done iconv -t utf-8 $* | pandoc $PANDOC_OPTS | iconv -f utf-8 diff --git a/markdown2latex b/markdown2latex index 59a467fbc..0fc2077cb 100644 --- a/markdown2latex +++ b/markdown2latex @@ -1,11 +1,24 @@ #!/bin/sh -e # converts markdown to latex +pathfind () { # portable which(1), code taken from Debian Developer's Reference + OLDIFS="$IFS" + IFS=: + for _p in $PATH; do + if [ -x "$_p/$*" ]; then + IFS="$OLDIFS" + return 0 + fi + done + IFS="$OLDIFS" + return 1 +} + for p in pandoc; do - which $p >/dev/null 2>&1 || { - echo >&2 "You need '$p' to use this program!" - exit 1 - } + pathfind $p || { + echo >&2 "You need '$p' to use this program!" + exit 1 + } done iconv -t utf-8 $* | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8 diff --git a/markdown2pdf b/markdown2pdf index 4af407fb7..59c0ba634 100644 --- a/markdown2pdf +++ b/markdown2pdf @@ -1,34 +1,47 @@ #!/bin/sh # converts markdown to latex, then uses latex to make a PDF +pathfind () { # portable which(1), code taken from Debian Developer's Reference + OLDIFS="$IFS" + IFS=: + for _p in $PATH; do + if [ -x "$_p/$*" ]; then + IFS="$OLDIFS" + return 0 + fi + done + IFS="$OLDIFS" + return 1 +} + for p in pandoc pdflatex; do - which $p >/dev/null 2>&1 || { - echo >&2 "You need '$p' to use this program!" - exit 1 - } + pathfind $p || { + echo >&2 "You need '$p' to use this program!" + exit 1 + } done outfile= for option; do if [ -n "$prev" ]; then - eval "$prev=\$option" - prev= - shift - continue + eval "$prev=\$option" + prev= + shift + continue fi optarg=$(expr "x$option" : 'x[^=]*=\(.*\)') case $option in -h | --h | --help ) - help=1 - shift ;; + help=1 + shift ;; -o | --o | --output ) - prev=outfile - shift ;; + prev=outfile + shift ;; -o=* | --o=* | --output=* ) - outfile=$optarg - shift ;; + outfile=$optarg + shift ;; -* ) echo >&2 "$0: unknown option: $option; aborting" - exit 1 ;; + exit 1 ;; * ) break ;; esac done @@ -41,9 +54,9 @@ done infile=$1 if [ -z "$outfile" ]; then if [ -n "$infile" ]; then - outfile=${infile%.*}.pdf + outfile=${infile%.*}.pdf else - outfile='stdin.pdf' # input is STDIN, since no argument given + outfile='stdin.pdf' # input is STDIN, since no argument given fi fi @@ -61,9 +74,9 @@ pandoc $PANDOC_OPTS -w latex -s | \ iconv -f utf-8 > $TEMP/$BASE.tex && ( cd $TEMP if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then - echo >&2 "LaTeX errors:" - cat >&2 $BASE.log - exit 1 + echo >&2 "LaTeX errors:" + cat >&2 $BASE.log + exit 1 fi ) || exit $? |