Author serhiy.storchaka
Recipients BreamoreBoy, chris.jerdonek, georg.brandl, gvanrossum, gward, jcea, jerith, mark.dickinson, mrabarnett, otto, palfrey, pitrou, serhiy.storchaka, terry.reedy, tlynn
Date 2012-08-04.15:26:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1344093997.07.0.27288162918.issue1859@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012-08-04 15:26:37serhiy.storchakasetrecipients: + 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:37serhiy.storchakasetmessageid: <1344093997.07.0.27288162918.issue1859@psf.upfronthosting.co.za>
2012-08-04 15:26:36serhiy.storchakalinkissue1859 messages
2012-08-04 15:26:36serhiy.storchakacreate