Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rich/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ReprHighlighter(RegexHighlighter):

base_style = "repr."
highlights: ClassVar[Sequence[str]] = [
r"(?P<tag_start><)(?P<tag_name>[-\w.:|]*)(?P<tag_contents>[\w\W]*)(?P<tag_end>>)",
r"(?P<tag_start><)(?P<tag_name>[-\w.:|]*)(?P<tag_contents>[\w\W]*?)(?P<tag_end>>(?=<|$))",
r'(?P<attrib_name>[\w_]{1,50})=(?P<attrib_value>"?[\w_]+"?)?',
r"(?P<brace>[][{}()])",
_combine_regex(
Expand Down
22 changes: 22 additions & 0 deletions tests/test_highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,25 @@ def test_highlight_iso8601_regex(test: str, spans: List[Span]):
highlighter.highlight(text)
print(text.spans)
assert text.spans == spans

def test_repr_highlighter_adjacent_tags():
from rich.highlighter import ReprHighlighter

highlighter = ReprHighlighter()

text = highlighter("<a>content1</a><b>content2</b>")

tag_contents_spans = [
span for span in text.spans
if span.style == "repr.tag_contents"
]

assert len(tag_contents_spans) == 2

assert [
(span.start, span.end)
for span in tag_contents_spans
] == [
(2, 14),
(17, 29),
]