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.

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.