
Hi,
I'm looking for a way to wrap lines in archived messages.
Messages from some mail clients (eg. Gmail) have their lines wrapped to 72 chars in the archived version, while archived messages from others (eg. Thunderbird, Outlook) display unwrapped lines forcing the reader to scroll horizontally.
Looking at the HTML page source -- in both cases (wrapped and unwrapped) I see the message content is enclosed by PRE tags.
<HR> <!--beginarticle--> <PRE> Lorem ipsum dolor sit amet, consectetur ...
Ut enim ad minim veniam, quis nostrud ... </PRE> <!--endarticle--> <HR>
The template (article.html) contains the following:
...
<HR>
<!--beginarticle-->
%(body)s
<!--endarticle-->
<HR>
...
From what I can figure out, the PRE tags come from .../mailman/Mailman/Archiver/HyperArch.py in a block of code lines 1290 to 1314 ...
///////////////////////////////////////////
def format_article(self, article):
# called from add_article
# TBD: Why do the HTML formatting here and keep it in the
# pipermail database? It makes more sense to do the html
# formatting as the article is being written as html and toss
# the data after it has been written to the archive file.
lines = filter(None, article.body)
# Handle <HTML> </HTML> directives
if self.ALLOWHTML:
self.__processbody_HTML(lines)
self.__processbody_URLquote(lines)
if not self.SHOWHTML and lines:
lines.insert(0, '<PRE>')
lines.append('</PRE>')
else:
# Do fancy formatting here
if self.SHOWBR:
lines = map(lambda x:x + "<BR>", lines)
else:
for i in range(0, len(lines)):
s = lines[i]
if s[0:1] in ' \t\n':
lines[i] = '<P>' + s
article.html_body = lines
return article
////////////////////////////
And the lines in that block that seem responsible for the PRE tags are ...
lines.insert(0, '<PRE>')
lines.append('</PRE>')
My question is: Can those PRE tags be removed and replaced with something equivalent to PHP's "nl2br" (which inserts a line break BR in place of new line entries)?
A Google search for such an equivalent gives me ...
def nl2br(s): return '<br />\n'.join(s.split('\n'))
With zero understanding of Python my attempts to implement this have failed so far and I may well be barking up the wrong tree completely. Any clues or pointers gratefully received.
Thanks.