Debian Codegraph @

examples/highlighter.py

raw
1 """
2 This example demonstrates a simple text highlighter.
3 """
4
5 from rich.console import Console
6 from rich.highlighter import RegexHighlighter
7 from rich.theme import Theme
8
9
10 class EmailHighlighter(RegexHighlighter):
11 """Apply style to anything that looks like an email."""
12
13 base_style = "example."
14 highlights = [r"(?P<email>[\w-]+@([\w-]+\.)+[\w-]+)"]
15
16
17 theme = Theme({"example.email": "bold magenta"})
18 console = Console(highlighter=EmailHighlighter(), theme=theme)
19
20 console.print("Send funds to [email protected]")