diff options
| -rw-r--r-- | src/acit/util.py | 17 |
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 |
