neomutt: Rename render-prettyhtml to neomutt-renderhtml

Also ensure the temporary file

a) is always different, by using mktemp
and b) is always deleted with an EXIT trap
This commit is contained in:
Marty Oehme 2025-09-16 18:39:08 +02:00
parent 6b2a0e1918
commit 79a9c4a227
Signed by: Marty
GPG key ID: 4E535BC19C61886E
2 changed files with 6 additions and 4 deletions

View file

@ -2,7 +2,7 @@
text/html; open %s ; nametemplate=%s.html
# render html emails inline using magic (uncomment the line below to use lynx instead)
# text/html; lynx -assume_charset=%{charset} -display_charset=utf-8 -collapse_br_tags -dump %s; nametemplate=%s.html; copiousoutput
text/html; render-prettyhtml %s; nametemplate=%s.html; copiousoutput;
text/html; neomutt-renderhtml %s; nametemplate=%s.html; copiousoutput;
text/plain; $EDITOR %s ;
# show calendar invites

View file

@ -2,7 +2,11 @@
# render html as markdown and display in glow, supports syntax highlighting
# requires: html2text, glow or bat
# author: CEUK
fpath=/tmp/mutt.md
fpath=$(mktemp --suffix=-neomutt-render.html)
#shellcheck disable=SC2064 # we want to expand it instantly
trap "rm -f -- ${fpath@Q}" EXIT
perl -0777pe 's/(<code class="sourceCode\s?)(\w+?)(">)(.*?)(<\/code>)/\1\2\3\n```\2\n\4\n```\n\5/gs' "$1" | html2text | sed -re 's/^\s+(```(\w+)?)/\1/gm' -e 's/\x1b\[[6-9;]*m//g' >"$fpath"
@ -13,5 +17,3 @@ elif command -v glow >/dev/null 2>&1; then
else
sed 's/\x1b\[[6-9;]*m//g' <"$fpath"
fi
rm "$fpath" || exit 1