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

Method highlight

rich/highlighter.py:123–140  ·  view source on GitHub ↗
(self, text: Text)

Source from the content-addressed store, hash-verified

121 ]
122
123 def highlight(self, text: Text) -> None:
124 super().highlight(text)
125
126 # Additional work to handle highlighting JSON keys
127 plain = text.plain
128 append = text.spans.append
129 whitespace = self.JSON_WHITESPACE
130 for match in re.finditer(self.JSON_STR, plain):
131 start, end = match.span()
132 cursor = end
133 while cursor < len(plain):
134 char = plain[cursor]
135 cursor += 1
136 if char == ":":
137 append(Span(start, end, "json.key"))
138 elif char in whitespace:
139 continue
140 break
141
142
143class ISO8601Highlighter(RegexHighlighter):

Calls 3

SpanClass · 0.85
spanMethod · 0.80
highlightMethod · 0.45