blob: 65c081699f35caf62e66ca23a2b9286a3c589dbf (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
def lookahead(iterable): # https://stackoverflow.com/a/1630350
"""Pass through all values from the given iterable, augmented by the
information if there are more values to come after the current one
(True), or if it is the last value (False).
"""
# Get an iterator and pull the first value.
it = iter(iterable)
try:
last = next(it)
except StopIteration:
return
# Run the iterator to exhaustion (starting from the second value).
for val in it:
# Report the *previous* value (more to come).
yield last, False
last = val
# Report the last value.
yield last, True
def email2html(mailtext:str,extraclasses="",ispatch=False):
#print(mailtext)
from html import escape
if ispatch:
from pygments import highlight
from pygments.lexers import DiffLexer
from pygments.formatters import HtmlFormatter
extraclasses+=" highlight"
res='<article class="email %s"><p>'%extraclasses
mail=escape(mailtext)
if ispatch:
mail=highlight(mail,lexer=DiffLexer(),formatter=HtmlFormatter(style="monokai"))
else:
mail=mail.replace("\n\n","</p><p>").replace("\n","<br>")
res+=mail
res+="</p></article>"
return res
|