mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 18:18:22 +00:00
fix escaping issue
This commit is contained in:
parent
e3fdf33043
commit
193903dff5
2 changed files with 7 additions and 2 deletions
|
@ -46,7 +46,8 @@ _EscapeSubMethod = Callable[[_ReSubCallable, str], str] # Sub method of a compi
|
|||
|
||||
|
||||
def escape(
|
||||
markup: str, _escape: _EscapeSubMethod = re.compile(r"(\\*)(\[[a-z#\/@].*?\])").sub
|
||||
markup: str,
|
||||
_escape: _EscapeSubMethod = re.compile(r"(\\*)(\[[a-z#/@][^[]*?])").sub,
|
||||
) -> str:
|
||||
"""Escapes text so that it won't be interpreted as markup.
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import pytest
|
||||
|
||||
from rich.console import Console
|
||||
from rich.markup import RE_TAGS, MarkupError, Tag, _parse, escape, render
|
||||
from rich.errors import MarkupError
|
||||
from rich.markup import RE_TAGS, Tag, _parse, escape, render
|
||||
from rich.text import Span
|
||||
|
||||
|
||||
|
@ -39,6 +40,9 @@ def test_escape():
|
|||
assert escape("[@foo]") == "\\[@foo]"
|
||||
assert escape("[@]") == "\\[@]"
|
||||
|
||||
# https://github.com/Textualize/rich/issues/2187
|
||||
assert escape("[nil, [nil]]") == r"[nil, \[nil]]"
|
||||
|
||||
|
||||
def test_render_escape():
|
||||
console = Console(width=80, color_system=None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue