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

Function _parse

rich/markup.py:73–103  ·  view source on GitHub ↗

Parse markup in to an iterable of tuples of (position, text, tag). Args: markup (str): A string containing console markup

(markup: str)

Source from the content-addressed store, hash-verified

71
72
73def _parse(markup: str) -> Iterable[Tuple[int, Optional[str], Optional[Tag]]]:
74 """Parse markup in to an iterable of tuples of (position, text, tag).
75
76 Args:
77 markup (str): A string containing console markup
78
79 """
80 position = 0
81 _divmod = divmod
82 _Tag = Tag
83 for match in RE_TAGS.finditer(markup):
84 full_text, escapes, tag_text = match.groups()
85 start, end = match.span()
86 if start > position:
87 yield start, markup[position:start], None
88 if escapes:
89 backslashes, escaped = _divmod(len(escapes), 2)
90 if backslashes:
91 # Literal backslashes
92 yield start, "\\" * backslashes, None
93 start += backslashes * 2
94 if escaped:
95 # Escape of tag
96 yield start, full_text[len(escapes) :], None
97 position = end
98 continue
99 text, equals, parameters = tag_text.partition("=")
100 yield start, None, _Tag(text, parameters if equals else None)
101 position = end
102 if position < len(markup):
103 yield position, markup[position:], None
104
105
106def render(

Callers 3

test_parseFunction · 0.90
test_parse_linkFunction · 0.90
renderFunction · 0.85

Calls 1

spanMethod · 0.80

Tested by 2

test_parseFunction · 0.72
test_parse_linkFunction · 0.72