MCPcopy
hub / github.com/Textualize/rich / escape

Function escape

rich/markup.py:48–70  ·  view source on GitHub ↗

Escapes text so that it won't be interpreted as markup. Args: markup (str): Content to be inserted in to markup. Returns: str: Markup with square brackets escaped.

(
    markup: str,
    _escape: _EscapeSubMethod = re.compile(r"(\\*)(\[[a-z#/@][^[]*?])").sub,
)

Source from the content-addressed store, hash-verified

46
47
48def escape(
49 markup: str,
50 _escape: _EscapeSubMethod = re.compile(r"(\\*)(\[[a-z#/@][^[]*?])").sub,
51) -> str:
52 """Escapes text so that it won't be interpreted as markup.
53
54 Args:
55 markup (str): Content to be inserted in to markup.
56
57 Returns:
58 str: Markup with square brackets escaped.
59 """
60
61 def escape_backslashes(match: Match[str]) -> str:
62 """Called by re.sub replace matches."""
63 backslashes, text = match.groups()
64 return f"{backslashes}{backslashes}\\{text}"
65
66 markup = _escape(escape_backslashes, markup)
67 if markup.endswith("\\") and not markup.endswith("\\\\"):
68 return markup + "\\"
69
70 return markup
71
72
73def _parse(markup: str) -> Iterable[Tuple[int, Optional[str], Optional[Tag]]]:

Callers 7

test_escapeFunction · 0.90
test_render_escapeFunction · 0.90
walk_directoryFunction · 0.90
markupMethod · 0.70
export_htmlMethod · 0.70
escape_textMethod · 0.70

Calls

no outgoing calls

Tested by 3

test_escapeFunction · 0.72
test_render_escapeFunction · 0.72