Skip to content

Commit

Permalink
Fix tag RegEx
Browse files Browse the repository at this point in the history
Closes Textualize#3024

Updated regex pattern to improve color formatting. The `tag_contents` group was updated to exclude `<` character (`[^<]`), preventing the matching of tags that contain other tags inside. Additionally, a `*?` was used for a non-greedy match, making the group match as little as possible, thus avoiding overreaching matches.
  • Loading branch information
MicaelJarniac authored Jul 5, 2023
1 parent aca9467 commit 54f6f5d
Showing 1 changed file with 1 addition and 1 deletion.
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 = [
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>[^<]*?)(?P<tag_end>>)",
r'(?P<attrib_name>[\w_]{1,50})=(?P<attrib_value>"?[\w_]+"?)?',
r"(?P<brace>[][{}()])",
_combine_regex(
Expand Down

0 comments on commit 54f6f5d

Please sign in to comment.