-
-
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
[BUG] rich.text - Text.highlight_words() : highlights letters, not words #3184
Labels
Comments
The signature for This means you need to pass your words as, for example, a list: text.highlight_words(["one", "two", "three"], style="blue") In your original example, you should do: j.highlight_words(["json"], style="blue") Closing this issue - but feel free to let me know if you're still having trouble. |
I hope we solved your problem. If you like using Rich, you might also enjoy Textual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Using the Text class, I try to highlight a specific word in the text using the highlight_words() function. The word does get highlighted, however all other letters that match any letter in the highlight word within the Text object get highlighted as well.
The fact both the function and keyword use "words" and not "letters" indicates to me this is a bug. I looked at the source code and I think I see the problem.
This line of the code treats keyword "words" as an iterable which it is, as a string.
It ends up splitting the keyword string like this:
I think it's just missing split on the end like this. That changes the iterable to a list of words.
I made the change on my local text.py and get what I think should be the correct output. Works on 1 and 2 words with a space separating. I don't know if this would break any edge cases.
With that, the keyword string becomes this:
Or with a second word, 'json output', like this:
Platform
Click to expand
What platform (Win/Linux/Mac) are you running on? What terminal software are you using?
Linux OpenSuse Tumbleweed (2023-11-02) / Python 3.11.5 / Konsole 23.08.2 / rich 13.6.0
The text was updated successfully, but these errors were encountered: