aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVosjedev <vosje@vosjedev.net>2025-12-06 13:05:46 +0100
committerVosjedev <vosje@vosjedev.net>2025-12-06 13:05:46 +0100
commit1aeabe75267e3471c153fac159fd3e3f30942b35 (patch)
tree0b0414ea94f5c2e473ae5a2476d9ceaf5c44b7cd
parent9dcac761b114ccca60a3c9fd92ff488d15d377e4 (diff)
downloadacit-1aeabe75267e3471c153fac159fd3e3f30942b35.tar.gz
acit-1aeabe75267e3471c153fac159fd3e3f30942b35.tar.bz2
acit-1aeabe75267e3471c153fac159fd3e3f30942b35.tar.xz
Use softwrapping for emails, remove hardwrapping at 80 columns
removes hard newlines that are between 70 and 85 characters away from a previous one
-rw-r--r--src/acit/util.py17
1 files 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","</p><p>").replace("\n","<br>")
+ mail=escape(mailtext)
+ lastlf=0
+ while '\n' in mail:
+ newlf=mail.find('\n',lastlf)
+ if 70<newlf-lastlf<85:
+ replacement=' '
+ elif len(mail)>newlf+1 and mail[newlf+1]=="\n": # two newlines
+ replacement="</p><p>"
+ elif newlf-lastlf<=1: # ignore the second newline of 2
+ replacement=''
+ else:
+ replacement='<br>'
+
+ mail=mail[:newlf]+replacement+mail[newlf+1:]
+ lastlf=newlf+len(replacement)
res+=mail