Serhiy Storchaka added the comment:
I believe that the method of work with newlines is too application specific.
Someone may prefer empty line separated paragraphs, here is another recipe:
def wrap_paragraphs(text, width=70, **kwargs):
return [line for para in re.split(r'\n\s*\n', text) for line in
(textwrap.wrap(para, width, **kwargs) + [''])][:-1]
And here is another application-specific recipe:
def format_html_paragraphs(text, width=70, **kwargs):
return ''.join('<p>%s</p>' % '<br>'.join(textwrap.wrap(html.escape(para),
width, **kwargs)) para in re.split(r'\n\s*\n', text))
I don't see a one obvious way to solve this problem, so I suggest a recipe, not
a patch. In any case the specialized text-processing applications are not
likely to use textwrap because most output now uses non-monowidth fonts.
Textwrap is only for the simplest applications.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue1859>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com