Opened 18 years ago
Closed 18 years ago
#1123 closed enhancement (fixed)
wrap long lines
Reported by: | Rainer Sokoll | Owned by: | Bas van der Vlies |
---|---|---|---|
Priority: | normal | Component: | EmailtoTracScript |
Severity: | normal | Keywords: | email2trac line breaks |
Cc: | Trac Release: | 0.10 |
Description
Could you add a feature that wraps long lines in incoming emails for better reading in trac?
Attachments (3)
Change History (22)
comment:1 Changed 18 years ago by
Status: | new → assigned |
---|
comment:2 Changed 18 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:3 follow-up: 4 Changed 18 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Thanks a lot ;-). I will make it an option. How many chars can be put on a line. I will close it when i have applied the patch to trunk. Just for me a reminder
comment:4 Changed 18 years ago by
Replying to bas:
Thanks a lot ;-). I will make it an option. How many chars can be put on a line. I will close it when i have applied the patch to trunk.
Unfortunataly, I was way too fast.
A new problem araised: textwrap.fill
replaces every whitespace, including newlines, with a space.
For example:
word word word word word
will become
word word word word word
Maybe I can come up with a solution tomorrow.
comment:5 follow-up: 6 Changed 18 years ago by
Then this is the solution:
print textwrap.fill(a, width=70, replace_whitespace=False)
Can you test it
comment:6 Changed 18 years ago by
Replying to anonymous:
Then this is the solution:
print textwrap.fill(a, width=70, replace_whitespace=False)Can you test it
textwrap eats empty lines (\n\n). Also, its output is somewhat unpredictable. (I'm a bloody novice to python, so hopefully noone gets offended). At he moment, I have the feeling that textwrap is not the right tool for our problem.
comment:7 follow-up: 8 Changed 18 years ago by
It is the right tool. In python 2.4 it does not eat up the newlines. Maybe we have to set an option for python 2.3
comment:8 Changed 18 years ago by
Replying to anonymous:
It is the right tool. In python 2.4 it does not eat up the newlines. Maybe we have to set an option for python 2.3
You are correct. In my tests, I had this:
from textwrap import TextWrapper rainer = TextWrapper() rainer.replace_whitespace = False rainer.width = 70 s = 'some long text with line\nbreaks' print rainer.fill(s)
which seems to work slightly different from your (much easier) solution. BTW: I'm running python 2.4.1
comment:9 Changed 18 years ago by
Rainer i have just applied a patch to trunk that implements the textwrap functionality:
email2trac.conf:
use_textwrap: 72
can you test it? It will wrap line longer then 72 chars or something else if you want.
Changed 18 years ago by
comment:10 Changed 18 years ago by
As you can see here, the 2nd long line has extra linebreaks, I do not know why :-(
comment:12 Changed 18 years ago by
Rainer,
Can you replace:
body_text = textwrap.fill( body_text, width = self.USE_TEXTWRAP, replace_whitespace = False )
with
body_text = textwrap.fill( body_text, width = self.USE_TEXTWRAP)
Changed 18 years ago by
Attachment: | with_replace_whitespace.png added |
---|
comment:13 Changed 18 years ago by
comment:14 Changed 18 years ago by
Thanks, just read the docs and it only works on paragraphs ;-( So it see the whole text as one paragraph and it does not reset the counters.
comment:15 Changed 18 years ago by
A friend of mine sent me this snipplet. As mentioned before, I am a newbie to python, and this code is far beyond my skills, but maybe you can get valuable input.
import textwrap LINESEPARATOR = '\n' def breakString(str='', width=30): return LINESEPARATOR.join(textwrap.fill(s,width) for s in str.split(LINESEPARATOR)) if __name__ == '__main__': testString = 'asdfghjkl\nasdfghjkl\nasdfghjkl asdfghjkl\n\nasdfghjkl' print breakString(testString)
Changed 18 years ago by
Attachment: | email2trac.py.in.diff added |
---|
comment:16 Changed 18 years ago by
The attached patch seems to solve the problem. Also fixes http://www.trac-hacks.org/ticket/1295 ;-)
comment:17 Changed 18 years ago by
Thanks i will apply it to trunk and close the ticket if i have actually did it ;-),
comment:19 Changed 18 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
body_text = part.get_payload(decode=1)
tobody_text = textwrap.fill(part.get_payload(decode=1), 70)