Merge pull request #3589 from hhsiao/patch-4

Update utils.py
This commit is contained in:
Griatch 2024-08-11 10:21:29 +02:00 committed by GitHub
commit c4d8d9a116
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -473,7 +473,7 @@ def iter_to_str(iterable, sep=",", endsep=", and", addquote=False):
list_to_string = iter_to_str
iter_to_string = iter_to_str
re_empty = re.compile("\n\s*\n")
re_empty = re.compile("\n\\s*\n")
def compress_whitespace(text, max_linebreaks=1, max_spacing=2):
@ -494,7 +494,7 @@ def compress_whitespace(text, max_linebreaks=1, max_spacing=2):
# this allows the blank-line compression to eliminate them if needed
text = re_empty.sub("\n\n", text)
# replace groups of extra spaces with the maximum number of spaces
text = re.sub(f"(?<=\S) {{{max_spacing},}}", " " * max_spacing, text)
text = re.sub(fr"(?<=\S) {{{max_spacing},}}", " " * max_spacing, text)
# replace groups of extra newlines with the maximum number of newlines
text = re.sub(f"\n{{{max_linebreaks},}}", "\n" * max_linebreaks, text)
return text