Skip to content

textual.highlight

HighlightTheme

Contains the style definition for user with the highlight method.

guess_language

guess_language(code, path)

Guess the language based on the code and path. The result may be used in the highlight function.

Parameters:

Name Type Description Default
code str

The code to guess from.

required
path str | None

A path to the code.

required

Returns:

Type Description
str

The language, suitable for use with Pygments.

highlight

highlight(
    code,
    *,
    language=None,
    path=None,
    theme=HighlightTheme,
    tab_size=8
)

Apply syntax highlighting to a string.

Parameters:

Name Type Description Default
code str

A string to highlight.

required
language str | None

The language to highlight.

None
theme type[HighlightTheme]

A HighlightTheme class (type not instance).

HighlightTheme
tab_size int

Number of spaces in a tab.

8

Returns:

Type Description
Content

A Content instance which may be used in a widget.