]> git.madduck.net Git - etc/mutt.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

make HTML dumper smarter
authormartin f. krafft <madduck@madduck.net>
Thu, 31 Oct 2019 22:23:21 +0000 (11:23 +1300)
committermartin f. krafft <madduck@madduck.net>
Thu, 31 Oct 2019 22:23:21 +0000 (11:23 +1300)
.mutt/htmldump

index 565d512d43592056c9afe7664af66e03ae82f832..906bd6dc51f086e094b64abbf05be5ca8fb20df7 100755 (executable)
@@ -1,5 +1,46 @@
 #!/bin/sh
 
 #!/bin/sh
 
-exec elinks -anonymous -localhost -eval "set document.codepage.assume = '$2'" \
-  -eval "set document.browse.margin_width = 0" \
-  -force-html -dump -dump-charset utf-8 -dump-color-mode 0
+get_mutt_confvar() {
+  local ret;
+  ret=$(mutt -D | sed -rne "s,^${1}(=| 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 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