This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients BreamoreBoy, GraylinKim, bethard, denilsonsa, eric.araujo, paul.j3, rurpy2, zbysz
Date 2014-07-30.21:35:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1406756130.59.0.776467476206.issue12806@psf.upfronthosting.co.za>
In-reply-to
Content
In http://bugs.python.org/issue22029 argparse
CSS white-space: like control for individual text blocks

I propose a set of `str` subclasses that can be used to define the wrapping style of individual text blocks. The idea is adapted from the HTML '<pre>' tag, and the CSS white-space: option.

`argparse.WhitespaceStyle` is a cover class that defines various utility methods, including `_str_format` which handles all of the `%` formatting.  The individual subclasses implement their own version of `_split_lines` and `_fill_text`.  I chose a standard set of classes based on the CSS white-space options:

Normal() - full white space compression and wrapping.  This is the default default of text in `argparse`.

Pre() - preformatting, the same as the `Raw` formatters

NoWrap() - Pre plus whitespace compression

PreLine()

PreWrap()

In `HelpFormatter`, `_split_lines`, `_fill_lines`, `_str_format` delegate the action to text's own methods.  Plain text is handled as `Normal()`.

I also defined a `WSList` class.  This is a list of Style class objects. It has the same API as the Style classes, iterating over the items.

Where possible these methods try to return an object of the same type as self.
------------------

Here I demonstrate two ways that these classes could be used to implement a hybrid formatter.

The first is a simple adaptation of the `PareML` formatter from `paraformatter.py`.  It shows how a custom style class could be defined.

The second is defines a `preformat` function, which converts the text block into a `WSList`, a list of style text objects.  The wrappable paragraphs are `Normal()`, the preformatted indented lines are `Pre()`. Blank lines are `Pre(' ')`.

I've explored writing a `Hanging` class, which performs a hanging indent on list item sentences.
History
Date User Action Args
2014-07-30 21:35:30paul.j3setrecipients: + paul.j3, bethard, eric.araujo, zbysz, denilsonsa, BreamoreBoy, rurpy2, GraylinKim
2014-07-30 21:35:30paul.j3setmessageid: <1406756130.59.0.776467476206.issue12806@psf.upfronthosting.co.za>
2014-07-30 21:35:30paul.j3linkissue12806 messages
2014-07-30 21:35:30paul.j3create