@@ -3,6 +3,7 @@
33# uses an available program to fetch URL and tidy to normalize it first
44
55REQUIRED="tidy"
6+SYNOPSIS="converts HTML from a URL, file, or STDIN to markdown-formatted text."
67
78### common.sh
89
@@ -59,63 +60,46 @@ grab_url_with () {
5960 $prog "$@" "$url"
6061}
6162
62−add_option () {
63− options="$options$NEWLINE$1"
64−}
65−
66−options=
6763argument=
6864encoding=
6965grabber=
7066
7167# Parse command-line arguments
72−while [ $# -gt 0 ]; do
73− case "$1" in
74− -h|--help)
75− pandoc -h 2>&1 | sed -e 's/pandoc/html2markdown/' \
76− -e '/^[[:space:]]*\(-f\|-t\|-S\|-N\|-m\|-i\|-c\|-T\|-D\|-d\)/,/./d'\
77− 1>&2
78− err " -e ENCODING, --encoding=ENCODING"
79− err " Specify character encoding of input"
80− err " -g COMMAND, --grabber=COMMAND"
81− err " Specify command to be used to grab contents of URL"
82− exit 0 ;;
83− -v|--version)
84− pandoc -v 2>&1 | sed -e 's/pandoc/html2markdown/' 1>&2
85− exit 0 ;;
86− -e)
87− shift
88− encoding=$1 ;;
89− --encoding=*)
90− wholeopt=$1
91− # extract encoding from after =
92− encoding=${wholeopt#*=} ;;
93− -g)
94− shift
95− grabber=$1 ;;
96− --grabber=*)
97− wholeopt=$1
98− # extract encoding from after =
99− grabber=${wholeopt#*=} ;;
100− -o|--output|-b|--tab-stop|-H|--include-in-header| \
101− -A|--include-after-body|-C|-B|--include-before-body| \
102− -C|--custom-header|-T|--title-prefix)
103− add_option $1
104− shift
105− add_option $1 ;;
106− -*) add_option $1 ;;
107− *)
108− if [ -z "$argument" ]; then
109− argument=$1
110− else
111− err "Warning: extra argument '$1' will be ignored."
112− fi ;;
113− esac
114− shift
115−done
68+parse_arguments () {
69+ while [ $# -gt 0 ]; do
70+ case "$1" in
71+ --encoding=*)
72+ wholeopt="$1"
73+ # extract encoding from after =
74+ encoding="${wholeopt#*=}" ;;
75+ -e|--encoding|-encoding)
76+ shift
77+ encoding="$1" ;;
78+ --grabber=*)
79+ wholeopt="$1"
80+ # extract encoding from after =
81+ grabber="\"${wholeopt#*=}\"" ;;
82+ -g|--grabber|-grabber)
83+ shift
84+ grabber="$1" ;;
85+ *)
86+ if [ -z "$argument" ]; then
87+ argument="$1"
88+ else
89+ err "Warning: extra argument '$1' will be ignored."
90+ fi ;;
91+ esac
92+ shift
93+ done
94+ export encoding
95+ export grabber
96+ export argument
97+}
11698
117−# Unpack options. Now "$@" will hold the pandoc options.
118−oldifs="$IFS"; IFS="$NEWLINE"; set -- $options; IFS="$oldifs"
99+oldifs="$IFS"
100+IFS=$NEWLINE
101+parse_arguments $ARGS
102+IFS="$oldifs"
119103
120104inurl=
121105if [ -n "$argument" ] && ! [ -f "$argument" ]; then
@@ -164,11 +148,11 @@ else # assume UTF-8
164148fi
165149
166150if [ -z "$argument" ]; then
167− tidy -utf8 2>/dev/null | pandoc -r html -w markdown "$@"
151+ tidy -utf8 2>/dev/null | pandoc --ignore-args -r html -w markdown "$@"
168152else
169153 if [ -f "$argument" ]; then
170154 to_utf8 "$argument" |
171− tidy -utf8 2>/dev/null | pandoc -r html -w markdown "$@"
155+ tidy -utf8 2>/dev/null | pandoc --ignore-args -r html -w markdown "$@"
172156 else
173157 err "File '$argument' not found."
174158 exit 1