Text Utils
GitHub Link to Code.
Text utilities for string manipulation operations.
Provides utility methods for text wrapping, cleaning, and formatting.
- class mdxplain.utils.text_utils.TextUtils
Utility class for text manipulation operations.
Provides static methods for text wrapping, newline removal, and other string formatting operations commonly needed across the codebase.
Examples
>>> from mdxplain.utils.text_utils import TextUtils >>> text = "Very Long\nLabel Text" >>> wrapped = TextUtils.wrap_text(text, max_length=10) >>> print(wrapped) Very Long Label Text
- static wrap_text(text: str, max_length: int = 40) str
Remove newlines and wrap text at word boundaries.
Removes all n characters from the text and wraps the resulting text at word boundaries to fit within max_length characters per line.
Parameters
- textstr
Text that may contain n characters
- max_lengthint, default=40
Maximum characters per line
Returns
- str
Cleaned and wrapped text
Examples
>>> text = "Very Long\nLabel Text" >>> wrapped = TextUtils.wrap_text(text, max_length=10) >>> print(wrapped) Very Long Label Text
>>> text = "Contact" >>> wrapped = TextUtils.wrap_text(text, max_length=20) >>> print(wrapped) Contact
Notes
Uses textwrap.fill with break_long_words=False to ensure words are not broken mid-word, even if they exceed max_length.