@@ -104,11 +104,11 @@ if [ -n "$argument" ] && ! [ -f "$argument" ]; then
104 inurl="$argument"
104 inurl="$argument"
107if [ -n "$inurl" ]; then
109if [ -n "$inurl" ]; then
108 err "Attempting to fetch file from '$inurl'..."
110 err "Attempting to fetch file from '$inurl'..."
112 grabber_out=$THIS_TEMPDIR/grabber.out
112 grabber_out=$THIS_TEMPDIR/grabber.out
113 grabber_log=$THIS_TEMPDIR/grabber.log
113 grabber_log=$THIS_TEMPDIR/grabber.log
114 if ! grab_url_with "$inurl" "$grabber" 1>$grabber_out 2>$grabber_log; then
114 if ! grab_url_with "$inurl" "$grabber" 1>$grabber_out 2>$grabber_log; then
@@ -144,14 +144,19 @@ else # assume UTF-8
144 alias to_utf8='cat'
144 alias to_utf8='cat'
147+htmlinput=$THIS_TEMPDIR/htmlinput
147if [ -z "$argument" ]; then
149if [ -z "$argument" ]; then
148− tidy -asxhtml -utf8 2>/dev/null | pandoc --ignore-args -r html -w markdown "$@"
150+ to_utf8 > $htmlinput # read from STDIN
151+elif [ -f "$argument" ]; then
152+ to_utf8 "$argument" > $htmlinput # read from file
150− if [ -f "$argument" ]; then
151− to_utf8 "$argument" |
152− tidy -asxhtml -utf8 2>/dev/null | pandoc --ignore-args -r html -w markdown "$@"
154− err "File '$argument' not found."
154+ err "File '$argument' not found."
158+if ! cat $htmlinput | pandoc --ignore-args -r html -w markdown "$@" ; then
159+ err "Failed to parse HTML. Trying again with tidy..."
160+ tidy -q -asxhtml -utf8 $htmlinput | \
161+ pandoc --ignore-args -r html -w markdown "$@"