[text] add 'sanitize_whitespace()'

This commit is contained in:
Mike Fährmann
2025-07-19 20:49:03 +02:00
parent 923e27f4fd
commit 7bb4053396
2 changed files with 16 additions and 0 deletions

View File

@@ -66,6 +66,11 @@ def slugify(value):
return re(r"[-\s]+").sub("-", value).strip("-_")
def sanitize_whitespace(value):
"""Replace all whitespace characters with a single space"""
return re(r"\s+").sub(" ", value.strip())
def ensure_http_scheme(url, scheme="https://"):
"""Prepend 'scheme' to 'url' if it doesn't have one"""
if url and not url.startswith(("https://", "http://")):