Example #1
0
def _make_rich_rext(*,
                    text: str,
                    style: str = "",
                    markup_mode: MarkupMode) -> Union[Markdown, Text]:
    """Take a string, remove indentations, and return styled text.

    By default, return the text as a Rich Text with the request style.
    If `rich_markdown_enable` is `True`, also parse the text for Rich markup strings.
    If `rich_markup_enable` is `True`, parse as Markdown.

    Only one of `rich_markdown_enable` or `rich_markup_enable` can be True.
    If both are True, `rich_markdown_enable` takes precedence.
    """
    # Remove indentations from input text
    text = inspect.cleandoc(text)
    if markup_mode == MARKUP_MODE_MARKDOWN:
        text = Emoji.replace(text)
        return Markdown(text, style=style)
    if markup_mode == MARKUP_MODE_RICH:
        return highlighter(Text.from_markup(text, style=style))
    else:
        return highlighter(Text(text, style=style))
Example #2
0
def test_replace():
    assert Emoji.replace("my code is :pile_of_poo:") == "my code is 💩"
Example #3
0
def test_emoji():
    from rich.emoji import Emoji

    log.debug(":thumbs_up:")
    assert Emoji.replace(":thumbs_up:") in handler.console.file.getvalue()
Example #4
0
def test_variant():
    print(repr(Emoji.replace(":warning:")))
    assert Emoji.replace(":warning:") == "âš "
    assert Emoji.replace(":warning-text:") == "âš " + "\uFE0E"
    assert Emoji.replace(":warning-emoji:") == "âš " + "\uFE0F"
    assert Emoji.replace(":warning-foo:") == ":warning-foo:"