MCPcopy Index your code
hub / github.com/clips/pattern / collapse_linebreaks

Function collapse_linebreaks

pattern/web/__init__.py:870–878  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

868 return "\n".join(p)
869
870def 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
880def plaintext(html, keep=[], replace=blocks, linebreaks=2, indentation=False):
881 """ Returns a string with all HTML tags removed.

Callers 1

plaintextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…