-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the bug
It's a bit of an edge case, but right now it's not possible to output a backslash immediately before a square bracket starting a markup token. While it does properly output a single backslash if you feed in r'\\' followed by a markup token, it still disables interpreting the token as markup.
To Reproduce
Working cases:
rich.print(r'[bold]text[/]') prints "text"
rich.print(r'\[not a tag]') prints "[not a tag]"
Not working case:
rich.print(r'\\[bold]some text[/]') gives an error about an unexpected close tag, because it doesn't treat "[bold]" as markup. The expected result here was "\text", a single backslash followed by the text in bold.
Adding more backslashes also produces a surprising result. It seems like the rightmost backslash is always consumed to disable markup on the square bracket, but all the previous backslashes are passed through as-is, rather than having every other backslash escape the following one. So, with three backslashes, I was expecting one to be output (consuming the first two of the input) and one to be left over to escape the square bracket and disable markup. WIth four backslashes, I was expecting two backslashes to be output (consuming all four of the input) and the square bracket after that to be treated as markup.
Platform
Rich 9.5.1 on macOS Mojave (10.14.6) with Apple's Terminal.app.