From eb6b5ef87a762a2480981b616a49cf0bba617daf Mon Sep 17 00:00:00 2001 From: Dennis Brakhane Date: Sat, 5 Feb 2022 19:12:21 +0100 Subject: [PATCH] Add support for enum.Flag in ReprHighlighter enum.Flag allows more than one bit to be set, and its repr will show something like . For this to display correctly, we need to add the pipe symbol to the tag regex. --- rich/highlighter.py | 2 +- tests/test_highlighter.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/rich/highlighter.py b/rich/highlighter.py index 8afdd017..e2ef9d7b 100644 --- a/rich/highlighter.py +++ b/rich/highlighter.py @@ -81,7 +81,7 @@ class ReprHighlighter(RegexHighlighter): base_style = "repr." highlights = [ - r"(?P\<)(?P[\w\-\.\:]*)(?P[\w\W]*?)(?P\>)", + r"(?P\<)(?P[\w\-\.\:\|]*)(?P[\w\W]*?)(?P\>)", r"(?P[\w_]{1,50})=(?P\"?[\w_]+\"?)?", r"(?P[\{\[\(\)\]\}])", _combine_regex( diff --git a/tests/test_highlighter.py b/tests/test_highlighter.py index 99793723..c5303b5c 100644 --- a/tests/test_highlighter.py +++ b/tests/test_highlighter.py @@ -40,6 +40,16 @@ highlight_tests = [ Span(4, 9, "repr.str"), ], ), + ( + "", + [ + Span(0, 1, "repr.tag_start"), + Span(1, 23, "repr.tag_name"), + Span(23, 25, "repr.tag_contents"), + Span(25, 26, "repr.tag_end"), + Span(24, 25, "repr.number"), + ], + ), ("( )", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]), ("[ ]", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]), ("{ }", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]),