view.dom.core

Functions

html_context()

Enter a context in which HTML nodes can be created under a fresh tree.

html_response(function)

Return a Response object from a function returning HTML.

Classes

HTMLNode(node_name, is_real, text, ...)

Data class representing an HTML node in the tree.

class HTMLNode(node_name: str, is_real: bool = True, text: str = '', attributes: ~collections.abc.MutableMapping[str, str] = <factory>, children: ~collections.abc.MutableSequence[~view.dom.core.HTMLNode] = <factory>)

Bases: SupportsJavaScript

Data class representing an HTML node in the tree.

as_html() str

Convert this node to HTML code.

as_html_stream() Iterator[str]

Convert this node to actual HTML code, streaming each line individually.

as_javascript() str

Convert this object into a single JavaScript expression.

attributes: MutableMapping[str, str]

Dictionary containing attribute names and values as they will be rendered in the final output.

children: MutableSequence[HTMLNode]

All nodes that are a direct descendant of this node.

is_real: bool

Whether this node will actually be included in the output. Generally, most nodes will be rendered, but there are a few special types of nodes that are only used during the rendering process.

classmethod new(name: str, *, child_text: str | None = None, attributes: MutableMapping[str, str] | None = None) HTMLNode

Create a new node that will be included in the final HTML.

node_name: str

Name of the node as it will appear in the HTML. For example, in an <html> node, this will be the string ‘html’.

node_stack: ClassVar[ContextVar[LifoQueue[HTMLNode]]] = <ContextVar name='node_stack'>
text: str

The direct text of this node, not including any other children.

classmethod virtual(name: str) HTMLNode

Create a new “fake” node.

html_response(function: HTMLView) RouteView

Return a Response object from a function returning HTML.