fix escaping issue

This commit is contained in:
Will McGugan 2022-04-12 14:16:54 +01:00
parent e3fdf33043
commit 193903dff5
2 changed files with 7 additions and 2 deletions

View file

@ -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.

View file

@ -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)