Message167412
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. |
|
Date |
User |
Action |
Args |
2012-08-04 15:26:37 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, gvanrossum, gward, georg.brandl, terry.reedy, jcea, mark.dickinson, tlynn, pitrou, palfrey, jerith, mrabarnett, chris.jerdonek, BreamoreBoy, otto |
2012-08-04 15:26:37 | serhiy.storchaka | set | messageid: <1344093997.07.0.27288162918.issue1859@psf.upfronthosting.co.za> |
2012-08-04 15:26:36 | serhiy.storchaka | link | issue1859 messages |
2012-08-04 15:26:36 | serhiy.storchaka | create | |
|