summaryrefslogtreecommitdiff
path: root/html2markdown
diff options
context:
space:
mode:
authorroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-11-12 12:11:25 +0000
committerroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-11-12 12:11:25 +0000
commit3ed8fc8784496722af85b6ec2ff5120c75db84dc (patch)
treec372051cd084ff53a7996a1a54e3c1c54d847b2e /html2markdown
parent69e23af8e4198dc4e308935855662248a31c6dc2 (diff)
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
Diffstat (limited to 'html2markdown')
-rw-r--r--html2markdown31
1 files changed, 17 insertions, 14 deletions
diff --git a/html2markdown b/html2markdown
index fb5734f39..48232acbb 100644
--- a/html2markdown
+++ b/html2markdown
@@ -2,22 +2,22 @@
# converts html to markdown
# uses an available program to fetch URL and tidy to normalize it first
-[ -n "$(which pandoc)" ] || {
- echo >&2 "You need 'pandoc' to use this program!"
- exit 1
-}
-[ -n "$(which tidy)" ] || {
- echo >&2 "You need 'tidy' to use this program!"
- exit 1
-}
+for p in pandoc tidy; do
+ which $p >/dev/null 2>&1 || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
+done
-if [ -z "$1" ] || [ -f $1 ]; then
- tidy -utf8 $1 2>/dev/null | pandoc $PANDOC_OPTS -r html -w markdown -s | iconv -f utf-8
+if [ -z "$1" ] || [ -f $1 ]; then
+ tidy -utf8 $1 2>/dev/null | \
+ pandoc $PANDOC_OPTS -r html -w markdown -s | \
+ iconv -f utf-8
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; then
+ if which $p >/dev/null 2>&1; then
DUMPER=$p
break
fi
@@ -30,10 +30,13 @@ else
curl) OPT="" ;;
links) OPT="-source" ;;
w3c) OPT="-n -get" ;;
- "") echo -n >&2 "Needs a program to fetch the URL "
- echo -n >&2 "(e.g. wget, w3m, lynx, w3c, or curl)."
+ "") printf "Needs a program to fetch the URL " >&2
+ printf "(e.g. wget, w3m, lynx, w3c, or curl)." >&2
exit 1 ;;
esac
# Fetch and feed to pandoc.
- $DUMPER $OPT $1 2>/dev/null | tidy -utf8 2>/dev/null | pandoc $PANDOC_OPTS -r html -w markdown -s | iconv -f utf-8
+ $DUMPER $OPT $1 2>/dev/null | \
+ tidy -utf8 2>/dev/null | \
+ pandoc $PANDOC_OPTS -r html -w markdown -s | \
+ iconv -f utf-8
fi