Equivalent of textwrap.dedent that ignores unindented first line.
(text: str)
| 13 | |
| 14 | |
| 15 | def _dedent(text: str) -> str: |
| 16 | """Equivalent of textwrap.dedent that ignores unindented first line.""" |
| 17 | |
| 18 | if text.startswith("\n"): |
| 19 | # text starts with blank line, don't ignore the first line |
| 20 | return textwrap.dedent(text) |
| 21 | |
| 22 | # split first line |
| 23 | splits = text.split("\n", 1) |
| 24 | if len(splits) == 1: |
| 25 | # only one line |
| 26 | return textwrap.dedent(text) |
| 27 | |
| 28 | first, rest = splits |
| 29 | # dedent everything but the first line |
| 30 | rest = textwrap.dedent(rest) |
| 31 | return "\n".join([first, rest]) |
| 32 | |
| 33 | |
| 34 | def wrap_paragraphs(text: str, ncols: int = 80) -> list[str]: |
no outgoing calls
no test coverage detected
searching dependent graphs…