This commit is contained in:
Will McGugan 2021-01-07 11:49:02 +00:00
parent e45d3d98ff
commit f15d6b8e54
3 changed files with 8 additions and 3 deletions

View File

@ -26,7 +26,7 @@ There is a shorthand for closing a style. If you omit the style name from the cl
These markup tags may be use in combination with each other and don't need to be strictly nested. The following examples demonstrates overlapping of markup tags::
print("[bold]Bold[italic] bold and italic [/bold] italic[/italic]")
print("[bold]Bold[italic] bold and italic [/bold]italic[/italic]")
Errors
~~~~~~

View File

@ -1,5 +1,5 @@
import re
from typing import Iterable, List, NamedTuple, Optional, Tuple, Union
from typing import Iterable, List, Match, NamedTuple, Optional, Tuple, Union
from .errors import MarkupError
from .style import Style
@ -46,7 +46,7 @@ def escape(markup: str, _escape=re.compile(r"(\\*)(\[[a-z#\/].*?\])").sub) -> st
str: Markup with square brackets escaped.
"""
def escape_backslashes(match: re.Match[str]) -> str:
def escape_backslashes(match: Match[str]) -> str:
"""Called by re.sub replace matches."""
backslashes, text = match.groups()
return f"{backslashes}{backslashes}\\{text}"

View File

@ -24,9 +24,14 @@ def test_re_match():
def test_escape():
# Potential tags
assert escape("foo[bar]") == r"foo\[bar]"
assert escape(r"foo\[bar]") == r"foo\\\[bar]"
# Not tags (escape not required)
assert escape("[5]") == "[5]"
assert escape("\\[5]") == "\\[5]"
def test_render_escape():
console = Console(width=80, color_system=None)