From 1aeabe75267e3471c153fac159fd3e3f30942b35 Mon Sep 17 00:00:00 2001 From: Vosjedev Date: Sat, 6 Dec 2025 13:05:46 +0100 Subject: Use softwrapping for emails, remove hardwrapping at 80 columns removes hard newlines that are between 70 and 85 characters away from a previous one --- src/acit/util.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/acit/util.py b/src/acit/util.py index d0f5fda..568f648 100644 --- a/src/acit/util.py +++ b/src/acit/util.py @@ -18,7 +18,6 @@ def lookahead(iterable): # https://stackoverflow.com/a/1630350 yield last, True def email2html(mailtext:str,extraclasses="",ispatch=False): - #print(mailtext) from html import escape if ispatch: from pygments import highlight @@ -33,7 +32,21 @@ def email2html(mailtext:str,extraclasses="",ispatch=False): if ispatch: mail=highlight(mailtext,lexer=DiffLexer(),formatter=HtmlFormatter(style="monokai")) else: - mail=escape(mailtext).replace("\n\n","

").replace("\n","
") + mail=escape(mailtext) + lastlf=0 + while '\n' in mail: + newlf=mail.find('\n',lastlf) + if 70newlf+1 and mail[newlf+1]=="\n": # two newlines + replacement="

" + elif newlf-lastlf<=1: # ignore the second newline of 2 + replacement='' + else: + replacement='
' + + mail=mail[:newlf]+replacement+mail[newlf+1:] + lastlf=newlf+len(replacement) res+=mail -- cgit