git.iko.soy/typeable/pandoc
on master help sign in
Modified html2markdown. Previously html2markdown piped all input
a1ad3b4fiddlosopher
src/wrappers/html2markdown.in+15−10
@@ -104,11 +104,11 @@ if [ -n "$argument" ] && ! [ -f "$argument" ]; then
104 inurl="$argument"
104 inurl="$argument"
105fi
105fi
106
106
107+### tempdir.sh
108+
107if [ -n "$inurl" ]; then
109if [ -n "$inurl" ]; then
108 err "Attempting to fetch file from '$inurl'..."
110 err "Attempting to fetch file from '$inurl'..."
109
111
110− ### tempdir.sh
111−
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'
145fi
145fi
146
146
147+htmlinput=$THIS_TEMPDIR/htmlinput
148+
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
149else
153else
150− if [ -f "$argument" ]; then
151− to_utf8 "$argument" |
152− tidy -asxhtml -utf8 2>/dev/null | pandoc --ignore-args -r html -w markdown "$@"
153− else
154− err "File '$argument' not found."
154+ err "File '$argument' not found."
155− exit 1
155+ exit 1
156− fi
156+fi
157+
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 "$@"
157fi
162fi