Html

class dsviper.Html

Bases: object

Renders Viper data as HTML, in two stages. Every method is static.

The renderers return a FRAGMENT, not a page: value(), value_pretty(), type(), dsm_definitions() and documents_details() each answer a run of markup carrying CSS class names.

The assemblers wrap one into a page: style() answers a <style> element defining those classes, body() wraps a fragment in a <body>, and document(title, style, body) takes what those two answered and returns a complete page - Html.document(t, Html.style(), Html.body(content)).

Every string a value or a declaration carries is HTML-escaped on the way out, so stored text cannot reach the page as markup.

Note: Not directly instantiable.

static body(content: str) → str

Wrap a rendered fragment in a <body> element, for document().

content is inserted as it is, not escaped: pass a fragment a renderer answered.

static document(title: str, style: str, body: str) → str

Return a complete HTML page.

title is HTML-escaped. style and body are what style() and body() answered; they are inserted as they are, not wrapped or escaped again.

static documents_details(documents: list[DocumentNode], show_type: bool = False) → str

Return the document trees - the roots DocumentNode.create_documents() answered - as nested markup: a node holding others is a <details> the reader opens, and a leaf is a <div> row.

With show_type, each row carries its element type.

static dsm_definitions(definitions: DSMDefinitions, show_documentation: bool = False, show_runtime_id: bool = False) → str

Return the HTML representation of the DSMDefinitions.

static style() → str

Return a <style> element defining the CSS classes the renderers emit.

Pass it to document(), or substitute your own sheet defining the same classes.

static type(type: Type) → str

Return the representation of the type in HTML.

static value(value: Value, use_description: bool = False) → str

Return the representation of the value in HTML.

static value_pretty(value: Value, show_type: bool = False) → str

Return the value as a nested, indented block, one element per line.

value() answers the same content inline, on one run. With show_type, each line carries its element type.