rich.highlighter

class rich.highlighter.Highlighter[source]

Abstract base class for highlighters.

__call__(text)[source]

Highlight a str or Text instance.

Parameters

text (Union[str, ~Text]) – Text to highlight.

Raises

TypeError – If not called with text or str.

Returns

A test instance with highlighting applied.

Return type

Text

abstract highlight(text)[source]

Apply highlighting in place to text.

Parameters

text (~Text) – A text object highlight.

Return type

None

class rich.highlighter.ISO8601Highlighter[source]

Highlights the ISO8601 date time strings. Regex reference: https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s07.html

class rich.highlighter.JSONHighlighter[source]

Highlights JSON

highlight(text)[source]

Highlight rich.text.Text using regular expressions.

Parameters

text (~Text) – Text to highlighted.

Return type

None

class rich.highlighter.NullHighlighter[source]

A highlighter object that doesn’t highlight.

May be used to disable highlighting entirely.

highlight(text)[source]

Nothing to do

Parameters

text (Text) –

Return type

None

class rich.highlighter.RegexHighlighter[source]

Applies highlighting from a list of regular expressions.

highlight(text)[source]

Highlight rich.text.Text using regular expressions.

Parameters

text (~Text) – Text to highlighted.

Return type

None

class rich.highlighter.ReprHighlighter[source]

Highlights the text typically produced from __repr__ methods.