X-Git-Url: https://git.madduck.net/etc/mutt.git/blobdiff_plain/91e68e854725d35f09a09b4a60b525e81d8186f6..f52c41fd7253335fa0251236b739ea36b9259cac:/.mutt/htmldump?ds=inline diff --git a/.mutt/htmldump b/.mutt/htmldump index d8d9ff7..c15ecd1 100755 --- a/.mutt/htmldump +++ b/.mutt/htmldump @@ -1,5 +1,51 @@ #!/bin/sh -exec elinks -anonymous -localhost -eval "set document.codepage.assume = '$2'" \ - -force-html -dump -dump-charset utf-8 -dump-color-mode 0 | - sed -re 's,^[[:space:]]{3},,' +get_mutt_confvar() { + local ret; + ret=$(mutt -Q "$1" | sed -rne "s,\S+(=| is ),,p") + case "$ret" in + (set) echo return 0;; + (unset) echo return 1;; + ('') echo "${2:-}"; return 1;; + (*) echo "$ret";; + esac +} + +WRAP=$(get_mutt_confvar wrap 0) +if [ $WRAP -lt 0 ]; then + WIDTH=$((${COLUMNS:-78} + $WRAP)) + +elif [ $WRAP -gt 0 ]; then + WIDTH=$WRAP + +fi + +if command -v html2markdown >/dev/null; then + + exec html2markdown --asterisk-emphasis --body-width=$WIDTH --unicode-snob \ + --no-skip-internal-links --links-after-para --no-wrap-links \ + --decode-errors=replace --images-to-alt - "$2"| \ + sed -re 's,^\\--[[:space:]]+$,-- ,' + +elif command -v pandoc >/dev/null; then + + exec iconv -f "$2" -t utf-8 | pandoc -s -f html -t markdown_mmd \ + --columns=$WIDTH + +elif command -v elinks >/dev/null; then + + exec elinks -anonymous -localhost -eval "set document.codepage.assume = '$2'" \ + -dump-width $WIDTH \ + -eval "set document.browse.margin_width = 0" \ + -force-html -dump -dump-charset utf-8 -dump-color-mode 0 + +elif command -v w3m >/dev/null; then + + exec w3m -I "$2" -O utf-8 -T text/html -dump -cols $WIDTH + +else + + echo >&2 No HTML to text converter found. + exit 1 + +fi