@@ -3,6 +3,7 @@
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
5REQUIRED="tidy"
5REQUIRED="tidy"
6+SYNOPSIS="converts HTML from a URL, file, or STDIN to markdown-formatted text."
7### common.sh
8### common.sh
@@ -59,63 +60,46 @@ grab_url_with () {
59 $prog "$@" "$url"
60 $prog "$@" "$url"
63− options="$options$NEWLINE$1"
71# Parse command-line arguments
67# Parse command-line arguments
72−while [ $# -gt 0 ]; do
69+ while [ $# -gt 0 ]; do
73− case "$1" in
70+ case "$1" in
75− pandoc -h 2>&1 | sed -e 's/pandoc/html2markdown/' \
76− -e '/^[[:space:]]*\(-f\|-t\|-S\|-N\|-m\|-i\|-c\|-T\|-D\|-d\)/,/./d'\
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"
84− pandoc -v 2>&1 | sed -e 's/pandoc/html2markdown/' 1>&2
89− --encoding=*)
71+ --encoding=*)
90− wholeopt=$1
72+ wholeopt="$1"
91− # extract encoding from after =
73+ # extract encoding from after =
92− encoding=${wholeopt#*=} ;;
74+ encoding="${wholeopt#*=}" ;;
93− -g)
75+ -e|--encoding|-encoding)
95− grabber=$1 ;;
77+ encoding="$1" ;;
96− --grabber=*)
78+ --grabber=*)
97− wholeopt=$1
79+ wholeopt="$1"
98− # extract encoding from after =
80+ # extract encoding from after =
99− grabber=${wholeopt#*=} ;;
81+ grabber="\"${wholeopt#*=}\"" ;;
100− -o|--output|-b|--tab-stop|-H|--include-in-header| \
82+ -g|--grabber|-grabber)
101− -A|--include-after-body|-C|-B|--include-before-body| \
102− -C|--custom-header|-T|--title-prefix)
105− add_option $1 ;;
84+ grabber="$1" ;;
106− -*) add_option $1 ;;
108− if [ -z "$argument" ]; then
86+ if [ -z "$argument" ]; then
109− argument=$1
87+ argument="$1"
111− err "Warning: extra argument '$1' will be ignored."
89+ err "Warning: extra argument '$1' will be ignored."
117−# Unpack options. Now "$@" will hold the pandoc options.
99+oldifs="$IFS"
118−oldifs="$IFS"; IFS="$NEWLINE"; set -- $options; IFS="$oldifs"
100+IFS=$NEWLINE
101+parse_arguments $ARGS
121if [ -n "$argument" ] && ! [ -f "$argument" ]; then
105if [ -n "$argument" ] && ! [ -f "$argument" ]; then
@@ -164,11 +148,11 @@ else # assume UTF-8
166if [ -z "$argument" ]; then
150if [ -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 "$@"
169 if [ -f "$argument" ]; then
153 if [ -f "$argument" ]; then
170 to_utf8 "$argument" |
154 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 "$@"
173 err "File '$argument' not found."
157 err "File '$argument' not found."