-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tag RegEx #3025
Fix tag RegEx #3025
Conversation
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.
Added myself.
I'll be trying to write tests that check if this fix is working. |
Nevermind. I could not find where this kind of test is. |
You're not always going to be able to parse things perfectly. REPRs aren't a formal grammar, and there will always be output which break it. Happy to accept a PR that improves on it though. One thing to be aware of is performance. You might print a lot of text with Rich, and overly expensive regexes can be a problem. |
I'll see if there's an easy fix for this second problem I've encountered. The fix for the first one seems to work alright and is already on this PR. |
Well, simply removing the |
I found where the tests for this are, and will try to adapt them. |
Found a bug with my implementation regarding recursive tags. This should do the trick, but I'm yet to actually test it:
|
BeforeAfter |
Nevermind, it seems like Python's |
What I'm currently doing to patch it locally is this: # Fix Rich repr tags
# https://github.com/Textualize/rich/pull/3025
from rich.default_styles import DEFAULT_STYLES
from rich.highlighter import ReprHighlighter
from rich.style import Style
DEFAULT_STYLES["repr.tag_contents"] = Style.null()
ReprHighlighter.highlights[0] = r"(?P<tag_start><)(?P<tag_name>[-\w.:|]*)(?P<tag_contents>[^<]*?)(?P<tag_end>>)" |
Closing, assumed stale. But if you are still working on it, feel free to reopen. |
Type of changes
Checklist
Description
Closes #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.