@@ -2,22 +2,22 @@
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
5−[ -n "$(which pandoc)" ] || {
5+for p in pandoc tidy; do
6− echo >&2 "You need 'pandoc' to use this program!"
6+ which $p >/dev/null 2>&1 || {
9−[ -n "$(which tidy)" ] || {
10− echo >&2 "You need 'tidy' to use this program!"
7+ echo >&2 "You need '$p' to use this program!"
14−if [ -z "$1" ] || [ -f $1 ]; then
12+if [ -z "$1" ] || [ -f $1 ]; then
13+ tidy -utf8 $1 2>/dev/null | \
15− tidy -utf8 $1 2>/dev/null | pandoc $PANDOC_OPTS -r html -w markdown -s | iconv -f utf-8
14+ pandoc $PANDOC_OPTS -r html -w markdown -s | \
17 # Treat given argument as an URL. Locate a
17 # Treat given argument as an URL. Locate a
18 # sensible text based browser (note the order).
18 # sensible text based browser (note the order).
19 for p in wget lynx w3m curl links w3c; do
19 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
@@ -30,10 +30,13 @@ else
30 curl) OPT="" ;;
30 curl) OPT="" ;;
31 links) OPT="-source" ;;
31 links) OPT="-source" ;;
32 w3c) OPT="-n -get" ;;
32 w3c) OPT="-n -get" ;;
33− "") echo -n >&2 "Needs a program to fetch the URL "
33+ "") printf "Needs a program to fetch the URL " >&2
34− echo -n >&2 "(e.g. wget, w3m, lynx, w3c, or curl)."
34+ printf "(e.g. wget, w3m, lynx, w3c, or curl)." >&2
37 # Fetch and feed to pandoc.
37 # Fetch and feed to pandoc.
38+ $DUMPER $OPT $1 2>/dev/null | \
39+ tidy -utf8 2>/dev/null | \
38− $DUMPER $OPT $1 2>/dev/null | tidy -utf8 2>/dev/null | pandoc $PANDOC_OPTS -r html -w markdown -s | iconv -f utf-8
40+ pandoc $PANDOC_OPTS -r html -w markdown -s | \