File size: 379 Bytes
844c9ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""Small text helpers shared across modules."""

from __future__ import annotations

import re

# Zero-width space — used as a layout token separator by the renderer.
ZWSP = "​"

_WS_RE = re.compile(r"\s+")


def collapse_ws(text: str) -> str:
    """Collapse all runs of whitespace to single spaces and strip the ends."""
    return _WS_RE.sub(" ", str(text or "")).strip()