git.iko.soy/typeable/pandoc
on master help sign in
Modified html2markdown. Previously html2markdown piped all input

through html tidy before passing it to pandoc. This causes problems on certain sites (e.g. daringfireball.com/markdown) which have well-formed xhtml that causes tidy to choke. Solution is to try pandoc on the original HTML, and run it through tidy only if that fails. This means that a temp file is now always used, even when input comes from a local file or standard input. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1039 788f1e2b-df1e-0410-8736-df70ead52e1b

commita1ad3b4e5fde28e74787dd4af609ea7aaf5b8005 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateTue 2 Oct 2007, 02:08 (19 years ago) parent5f64258
1 file changed+15−10
src/wrappers/html2markdown.in+15−10
src/wrappers/html2markdown.in+15−10
@@ -104,11 +104,11 @@ if [ -n "$argument" ] && ! [ -f "$argument" ]; then
104104 inurl="$argument"
105105fi
106106
107+### tempdir.sh
108+
107109if [ -n "$inurl" ]; then
108110 err "Attempting to fetch file from '$inurl'..."
109111
110− ### tempdir.sh
111−
112112 grabber_out=$THIS_TEMPDIR/grabber.out
113113 grabber_log=$THIS_TEMPDIR/grabber.log
114114 if ! grab_url_with "$inurl" "$grabber" 1>$grabber_out 2>$grabber_log; then
@@ -144,14 +144,19 @@ else # assume UTF-8
144144 alias to_utf8='cat'
145145fi
146146
147+htmlinput=$THIS_TEMPDIR/htmlinput
148+
147149if [ -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
149153else
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."
155− exit 1
156− fi
154+ err "File '$argument' not found."
155+ exit 1
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 "$@"
157162fi