mirror of https://github.com/Textualize/rich.git
Add support for enum.Flag in ReprHighlighter
enum.Flag allows more than one bit to be set, and its repr will show something like <Permission.READ|WRITE: 3>. For this to display correctly, we need to add the pipe symbol to the tag regex.
This commit is contained in:
parent
880693db5b
commit
eb6b5ef87a
|
@ -81,7 +81,7 @@ class ReprHighlighter(RegexHighlighter):
|
||||||
|
|
||||||
base_style = "repr."
|
base_style = "repr."
|
||||||
highlights = [
|
highlights = [
|
||||||
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<attrib_name>[\w_]{1,50})=(?P<attrib_value>\"?[\w_]+\"?)?",
|
||||||
r"(?P<brace>[\{\[\(\)\]\}])",
|
r"(?P<brace>[\{\[\(\)\]\}])",
|
||||||
_combine_regex(
|
_combine_regex(
|
||||||
|
|
|
@ -40,6 +40,16 @@ highlight_tests = [
|
||||||
Span(4, 9, "repr.str"),
|
Span(4, 9, "repr.str"),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"<Permission.WRITE|READ: 3>",
|
||||||
|
[
|
||||||
|
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")]),
|
("[ ]", [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")]),
|
||||||
|
|
Loading…
Reference in New Issue