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
markupso it renders literally (no tags interpreted). Port ofrich.markup.escape: a\is inserted before every tag-opening[, any pre-existing backslashes are doubled, and a lone trailing\is doubled. - render
- Parse
markupinto styledText. - render_
emoji renderwith:emoji:codes replaced, as upstream’smarkup.render(emoji=True)does: only in the text between tags, one chunk at a time, so tag names and parameters are left alone and aMarkupErrorposition counts characters of the original string, not of the emoji-replaced one.- render_
with renderwith a basestylefor the whole text and, whenemojiis set,:emoji:codes replaced. Port ofmarkup.render(markup, style, emoji, emoji_variant): a string with no[is replaced whole, withemoji_variant, and not parsed.