summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2024-01-22 17:38:21 +0100
committerRobin Jarry <robin@jarry.cc>2024-03-10 19:29:21 +0100
commitd94969d8f669fb2b4c463a0267865379e30ff975 (patch)
tree41f14394744580f1cf5fb204c14ed04423565310
parent0e66dc8efcf7998d654333a7866be28b4db65fef (diff)
downloadaerc-d94969d8f669fb2b4c463a0267865379e30ff975.tar.gz
aerc-d94969d8f669fb2b4c463a0267865379e30ff975.zip
htmlquote: add example using string functions
Expand the htmlquote example with a more extensive version that makes an even more concise text by dropping empty lines, leading whitespaces (when the message is centered), and the links and references generated as an addendum. Signed-off-by: Moritz Poldrack <git@moritz.sh>
-rw-r--r--configurations/htmlquote.md40
1 files changed, 33 insertions, 7 deletions
diff --git a/configurations/htmlquote.md b/configurations/htmlquote.md
index 2e7d2def..630735f9 100644
--- a/configurations/htmlquote.md
+++ b/configurations/htmlquote.md
@@ -3,19 +3,45 @@ title: "aerc-wiki: Configurations/HTML quoting in replies"
---
Sometimes the email you get only has `text/html`. If you quote reply this, the
-default [quoted_reply
-template](https://git.sr.ht/~rjarry/aerc/tree/master/item/templates/quoted_reply)
-will dump the entire html with all the markup into the quote. You can update
-this template to behave differently if replying to html. For example, add the
-html filter shipped with aerc to construct a more sensible text to quote:
+default [quoted_reply template][quoted_reply] will dump the entire html with
+all the markup into the quote. You can update this template to behave
+differently if replying to html. For example, add the html filter shipped with
+aerc to construct a more sensible text to quote:
```
{{ if eq .OriginalMIMEType "text/html" -}}
-{{- trimSignature (exec `~/.local/softwarefromsource/aerc/filters/html` .OriginalText) | quote -}}
+ {{- trimSignature (exec `~/.local/softwarefromsource/aerc/filters/html` .OriginalText) | quote -}}
{{- else -}}
-{{- trimSignature .OriginalText | quote -}}
+ {{- trimSignature .OriginalText | quote -}}
{{- end}}
```
+This can be expanded to also properly quote html sent as text/plain and to make
+the filtered content more readable by dropping empty lines, links, and leading
+whitespace.
+
+```
+{{ if or
+ (eq .OriginalMIMEType "text/html")
+ (contains (toLower .OriginalText) "<html")
+}}
+ {{- $text := exec `/usr/lib/aerc/filters/html` .OriginalText | replace `\r` `` -}}
+ {{- range split "\n" $text -}}
+ {{- if eq . "References:" }}{{break}}{{end}}
+ {{- if or
+ (eq (len .) 0)
+ (match `^\[.+\]\s*$` .)
+ }}{{continue}}{{end}}
+ {{- printf "%s\n" . | replace `^[\s]+` "" | quote}}
+ {{- end -}}
+{{- else }}
+ {{- trimSignature .OriginalText | quote -}}
+{{- end -}}
+
+{{.Signature -}}
+```
+
Note, that since this filter comes with a third-party dependency (w3m), this
will not be added to the default template shipped with aerc.
+
+[quoted_reply]: https://git.sr.ht/~rjarry/aerc/tree/master/item/templates/quoted_reply