Returns a string with consecutive linebreaks collapsed to at most the given threshold. Whitespace on empty lines and at the end of each line is removed.
(string, threshold=1)
| 868 | return "\n".join(p) |
| 869 | |
| 870 | def collapse_linebreaks(string, threshold=1): |
| 871 | """ Returns a string with consecutive linebreaks collapsed to at most the given threshold. |
| 872 | Whitespace on empty lines and at the end of each line is removed. |
| 873 | """ |
| 874 | n = "\n" * threshold |
| 875 | p = [s.rstrip() for s in string.splitlines()] |
| 876 | string = "\n".join(p) |
| 877 | string = re.sub(n+r"+", n, string) |
| 878 | return string |
| 879 | |
| 880 | def plaintext(html, keep=[], replace=blocks, linebreaks=2, indentation=False): |
| 881 | """ Returns a string with all HTML tags removed. |
no outgoing calls
no test coverage detected
searching dependent graphs…