Equivalent of textwrap.dedent that ignores unindented first line. This means it will still dedent strings like: '''foo is a bar ''' For use in wrap_paragraphs.
(text)
| 357 | |
| 358 | |
| 359 | def dedent(text): |
| 360 | """Equivalent of textwrap.dedent that ignores unindented first line. |
| 361 | |
| 362 | This means it will still dedent strings like: |
| 363 | '''foo |
| 364 | is a bar |
| 365 | ''' |
| 366 | |
| 367 | For use in wrap_paragraphs. |
| 368 | """ |
| 369 | |
| 370 | if text.startswith('\n'): |
| 371 | # text starts with blank line, don't ignore the first line |
| 372 | return textwrap.dedent(text) |
| 373 | |
| 374 | # split first line |
| 375 | splits = text.split('\n',1) |
| 376 | if len(splits) == 1: |
| 377 | # only one line |
| 378 | return textwrap.dedent(text) |
| 379 | |
| 380 | first, rest = splits |
| 381 | # dedent everything but the first line |
| 382 | rest = textwrap.dedent(rest) |
| 383 | return '\n'.join([first, rest]) |
| 384 | |
| 385 | |
| 386 | def wrap_paragraphs(text, ncols=80): |
no outgoing calls