diff --git a/docs/source/highlighting.rst b/docs/source/highlighting.rst index 4f7fd737..b1d08098 100644 --- a/docs/source/highlighting.rst +++ b/docs/source/highlighting.rst @@ -13,9 +13,9 @@ If the default highlighting doesn't fit your needs, you can define a custom high Here's an example which highlights text that looks like an email address:: - - from rich.highlighter import RegexHighlighter - + from rich.console import Console + from rich.highlighter import RegexHighlighter + from rich.theme import Theme class EmailHighlighter(RegexHighlighter): """Apply style to anything that looks like an email.""" @@ -24,13 +24,8 @@ Here's an example which highlights text that looks like an email address:: highlights = [r"(?P[\w-]+@([\w-]+\.)+[\w-]+)"] - from rich.console import Console - from rich.style import Style - from rich.theme import Theme - theme = Theme({"example.email": "bold magenta"}) console = Console(highlighter=EmailHighlighter(), theme=theme) - console.print("Send funds to money@example.org") diff --git a/examples/highlighter.py b/examples/highlighter.py index 7b91c1e2..077508fa 100644 --- a/examples/highlighter.py +++ b/examples/highlighter.py @@ -1,4 +1,6 @@ +from rich.console import Console from rich.highlighter import RegexHighlighter +from rich.theme import Theme class EmailHighlighter(RegexHighlighter): @@ -8,10 +10,6 @@ class EmailHighlighter(RegexHighlighter): highlights = [r"(?P[\w-]+@([\w-]+\.)+[\w-]+)"] -from rich.console import Console -from rich.style import Style -from rich.theme import Theme - theme = Theme({"example.email": "bold magenta"}) console = Console(highlighter=EmailHighlighter(), theme=theme)