Skip to content

textual.markup

Utilities related to content markup.

MarkupError

Bases: Exception

An error occurred parsing content markup.

MarkupTokenizer

MarkupTokenizer()

Bases: TokenizerState

Tokenizes content markup.

StyleTokenizer

StyleTokenizer()

Bases: TokenizerState

Tokenizes a style

escape

escape(markup, _escape=sub)

Escapes text so that it won't be interpreted as markup.

Parameters:

Name Type Description Default

markup

str

Content to be inserted in to markup.

required

Returns:

Name Type Description
str str

Markup with square brackets escaped.

parse_style

parse_style(style, variables=None)

Parse a style with substituted variables.

Parameters:

Name Type Description Default

style

str

Style encoded in a string.

required

variables

dict[str, str] | None

Mapping of variables, or None to import from active app.

None

Returns:

Type Description
Style

A Style object.

to_content

to_content(markup, style='', template_variables=None)

Convert markup to Content.

Parameters:

Name Type Description Default

markup

str

String containing markup.

required

style

str | Style

Optional base style.

''

template_variables

Mapping[str, object] | None

Mapping of string.Template variables

None

Raises:

Type Description
MarkupError

If the markup is invalid.

Returns:

Type Description
Content

Content that renders the markup.