mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 10:08:40 +00:00
optimizations
This commit is contained in:
parent
4e6a82d773
commit
4eee177269
2 changed files with 5 additions and 3 deletions
|
@ -62,13 +62,15 @@ def _parse(markup: str) -> Iterable[Tuple[int, Optional[str], Optional[Tag]]]:
|
|||
|
||||
"""
|
||||
position = 0
|
||||
_divmod = divmod
|
||||
_Tag = Tag
|
||||
for match in RE_TAGS.finditer(markup):
|
||||
full_text, escapes, tag_text = match.groups()
|
||||
start, end = match.span()
|
||||
if start > position:
|
||||
yield start, markup[position:start], None
|
||||
if escapes:
|
||||
backslashes, escaped = divmod(len(escapes), 2)
|
||||
backslashes, escaped = _divmod(len(escapes), 2)
|
||||
if backslashes:
|
||||
# Literal backslashes
|
||||
yield start, "\\" * backslashes, None
|
||||
|
@ -79,7 +81,7 @@ def _parse(markup: str) -> Iterable[Tuple[int, Optional[str], Optional[Tag]]]:
|
|||
position = end
|
||||
continue
|
||||
text, equals, parameters = tag_text.partition("=")
|
||||
yield start, None, Tag(text, parameters if equals else None)
|
||||
yield start, None, _Tag(text, parameters if equals else None)
|
||||
position = end
|
||||
if position < len(markup):
|
||||
yield position, markup[position:], None
|
||||
|
|
|
@ -29,7 +29,7 @@ def test_escape():
|
|||
|
||||
|
||||
def test_render_escape():
|
||||
console = Console(color_system=None)
|
||||
console = Console(width=80, color_system=None)
|
||||
console.begin_capture()
|
||||
console.print(
|
||||
escape(r"[red]"), escape(r"\[red]"), escape(r"\\[red]"), escape(r"\\\[red]")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue