rurpy the second added the comment:

I happened upon this issue while Googling for a formatter with the behavior 
described here.

I put together a formatter derived from the code submitted by GraylinKim 
(2011-08-22) and offer it for consideration (though it is missing some things 
like docstrings and hasn't been tested very thoroughly).

As per other comments, it uses additional indentation rather than leading 
special characters to start a new block.  Differently than GraylinKim's code, 
additional indentation suppresses wrapping or any formatting.  However, it 
would be easy to change that as I hope is obvious from the code.

There are two common ways of denoting a block of text (a block being text that 
should be reformatted as a single unit; aka paragraph)

 1. A group of text lines ending with newlines followed by a blank line to 
denote the end of the block.

 2. A single (long) text line where the terminating newline denotes the end of 
the block (i.e. one line == one block).

Both occur in the context of argparse help text:

Example of #1:
   p.add_argument (....,
       help='''block1 block1 block1 block1 
           block1 block1 block1 block1
           block1 block1 block1 block1

           block2 block2 block2 block2
           block2 block2 block2 block2''')

Examples of #2:
   p.add_argument (....,
       help='block1 block1 block1 block1 '
           'block1 block1 block1 block1 '
           'block1 block1 block1 block1 \n'
           ''
           'block2 block2 block2 block2 '
           'block2 block2 block2 block2 ')

   p.add_argument (....,
       help='''block1 block1 block1 block1 \
           block1 block1 block1 block1 \
           block1 block1 block1 block1 \

           block2 block2 block2 block2 \
           block2 block2 block2 block2 ''')

There is no way, when reading lines of text, to tell whether one is reading 
text in the form of #1 or #2, when one sees a newline.  So a formatter really 
needs to be able to be told which form it is being given.  This seems to 
require two separate formatter classes (though they call common code.)

The first form (call it multiline blocked text) is formatted by 
ParagraphFormatterML.  The second form (call it single-line blocked text; I 
often use form #2a) by ParagraphFormatter.

----------
nosy: +rurpy2
Added file: http://bugs.python.org/file28091/paraformatter.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12806>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to