Skip to main content

Module markup

Module markup 

Source
Expand description

Console markup parsing.

Port of upstream rich/markup.py. Turns "[bold]Hello[/] [red]World[/]" into a Text with spans. Tags are resolved against a [Theme] first (so named styles like [warning] work) and otherwise parsed as inline style definitions via Style::parse.

A […] is only a tag when it starts with [a-z#/@] (matching upstream’s RE_TAGS), so [Hello] and [42] are literal text. \[ escapes a bracket, and an unmatched closing tag raises RichError::Markup. @-tags (meta/handlers) apply no visible style.

Structs§

Tag
A tag in console markup. Port of rich.markup.Tag.

Functions§

escape
Escape markup so it renders literally (no tags interpreted). Port of rich.markup.escape: a \ is inserted before every tag-opening [, any pre-existing backslashes are doubled, and a lone trailing \ is doubled.
render
Parse markup into styled Text.
render_emoji
render with :emoji: codes replaced, as upstream’s markup.render(emoji=True) does: only in the text between tags, one chunk at a time, so tag names and parameters are left alone and a MarkupError position counts characters of the original string, not of the emoji-replaced one.
render_with
render with a base style for the whole text and, when emoji is set, :emoji: codes replaced. Port of markup.render(markup, style, emoji, emoji_variant): a string with no [ is replaced whole, with emoji_variant, and not parsed.