Skip to content
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

Internal quote pairs cause unexpected coloring? #32

Closed
lillian27 opened this issue Apr 11, 2020 · 3 comments
Closed

Internal quote pairs cause unexpected coloring? #32

lillian27 opened this issue Apr 11, 2020 · 3 comments

Comments

@lillian27
Copy link

Nice module!

I've noticed the following odd behavior: when using rich.print with bbcode tags, if the string contains matching quotes the substring between the quotes is colored green.

from rich import print
# Contains a quote pair, Malley is printed in green
print("[bold]O'Malley's Bar[/bold]")

# Only one quote, prints as expected
print("[bold]O'Malleys Bar[/bold]")

I've tried this with a few different tags, swapping the internal quote types, and using Console.print() but all show the same behavior.

@lillian27
Copy link
Author

After using this more it looks like print is formatting the string as if it were python code. Quoted strings turn green, obvious numerics are purple. Keywords aren't affected. Also, all content inside of brackets is being eaten regardless of if it is a valid bbcode tag or not.

print("Is anything [in here] afterwards?")
Is anything  afterwards?

Bracketed non-tag content should just get passed through.

@willmcgugan
Copy link
Collaborator

Rich will highlight repr strings by default. I can probably harden the regex to avoid that issue, but in the meantime you can disable highlighting by passing highlight=False to Console.print or to the Console constructor.

Unknown tags are left in because the styles depend on the theme. You wouldn't want the text left in just because a theme was missing a style. You can disable the markup in the same way as highlighting with markup=False.

@willmcgugan
Copy link
Collaborator

In 0.8.11 you can escape quotes by doubling them up.

print("Is anything [[in here]] afterwards?")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants