add in splitting of regex callable func

This commit is contained in:
Nathan Page 2021-05-09 14:58:24 -07:00
parent d93e79f94d
commit fb4217acb1
3 changed files with 10 additions and 5 deletions

View File

@ -11,6 +11,7 @@ from rich.console import (
ConsoleRenderable,
RenderGroup,
RenderResult,
RenderableType,
)
from rich.markdown import Markdown
from rich.measure import Measurement
@ -95,7 +96,7 @@ def make_test_card() -> Table:
),
)
def comparison(renderable1: Any, renderable2: Any) -> Table:
def comparison(renderable1: RenderableType, renderable2: RenderableType) -> Table:
table = Table(show_header=False, pad_edge=False, box=None, expand=True)
table.add_column("1", ratio=1)
table.add_column("2", ratio=1)

View File

@ -5,11 +5,13 @@ import re
from ._emoji_codes import EMOJI
_EmojiSub = Callable[[Callable[[Match[str]], str], str], str]
_ReStringMatch = Match[str] # regex match object
_ReSubCallable = Callable[[_ReStringMatch], str] # Callable invoked by re.sub
_EmojiSubMethod = Callable[[_ReSubCallable, str], str] # Sub method of a compiled re
def _emoji_replace(
text: str, _emoji_sub: _EmojiSub = re.compile(r"(:(\S*?):)").sub
text: str, _emoji_sub: _EmojiSubMethod = re.compile(r"(:(\S*?):)").sub
) -> str:
"""Replace emoji code in text."""
get_emoji = EMOJI.get

View File

@ -36,11 +36,13 @@ class Tag(NamedTuple):
)
_EscapeSub = Callable[[Callable[[Match[str]], str], str], str]
_ReStringMatch = Match[str] # regex match object
_ReSubCallable = Callable[[_ReStringMatch], str] # Callable invoked by re.sub
_EscapeSubMethod = Callable[[_ReSubCallable, str], str] # Sub method of a compiled re
def escape(
markup: str, _escape: _EscapeSub = 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.