Skip to main content

Module export

Module export 

Source
Expand description

Exporting rendered output to HTML.

Port of rich/console.py’s export_html + the _export_format.py template. Turns a recorded stream of Segments (captured via Console::export_html) into a self-contained HTML document, using a TerminalTheme to resolve colors.

Both variants are ported: inline_styles (each span carries its own style="…") and the CSS-class stylesheet, with links and code_format.

Structs§

ExportFormatError
A code_format template that Python’s str.format would reject: an unknown field (KeyError), a positional or formatted field, or an unmatched brace (ValueError).

Constants§

CONSOLE_HTML_FORMAT
The HTML document template. Port of _export_format.CONSOLE_HTML_FORMAT, verbatim: a Python format string, so literal braces are doubled. Pass it (or your own, as upstream’s code_format=) to export_html_with.

Functions§

export_html_classes
Render segments to a self-contained HTML document using CSS classes and a generated stylesheet. Port of Console.export_html(inline_styles=False) (upstream’s default). Distinct styles are numbered .r1, .r2, … in the order first seen.
export_html_inline
Render segments to a self-contained HTML document with inline styles. Port of Console.export_html(inline_styles=True).
export_html_with
Render segments to HTML with every option of upstream’s Console.export_html: code_format replaces CONSOLE_HTML_FORMAT (fields {code}, {stylesheet}, {foreground}, {background}), and inline_styles chooses style="…" attributes over a class stylesheet.
format_template
Substitute {name} fields in a Python format string, with {{ and }} standing for literal braces: the subset of str.format upstream’s export templates use. Conversions (!r) and format specs (:>10) are refused.