Skip to content

Elements

  • Element - Abstract base for every renderable element. Implement tonode to describe how the element expands in the tree.
  • CustomAttribute - Base class for special attributes that expand into real HTML attributes at render time.
  • ElementContent - Sequence of child elements or strings accepted by most element constructors.
  • HTMLAttributeValue / HTMLAttributes - Accepted attribute shapes for HTML elements. Non-string primitives are converted.
  • lazy_element - Wrap a factory that receives the current Context when the element is rendered.
  • TextElement - Escapes text so it can be safely inserted into the DOM tree.
  • ScriptContent - Wrap inline script content, escaping closing tags to prevent premature termination.
  • ElementFactory - Protocol for callables that create elements.
  • El - A way to create html elements quickly. Write El.<tag name> or El["<tag name>"] to create an element with this tag name. You may specify attributes by passing them as key values parameters. The inner content is set by specifying the list content with str | Element as children. Example:

    # left underscores are stripped from attribute names
    El.div(_class="button", content=["click me"])
    

  • VEl - A way to create html void elements (like input, meta, link etc.) quickly. Write VEl.<tag name> or VEl["<tag name>"] to create an element with this tag name. You may specify attributes by passing them as key values parameters. Void elements have no inner content.

    # left underscores are stripped from attribute names
    VEl.input(_type="text")
    

  • UnescapedHTMLElement - Use this to return raw html strings. Example: UnescapedHTMLElement("<h1>Hello World</h1>")

  • HTMLFragment - To create fragments, a container for elements on the same level. Works like react fragments.

  • KeyedElement - Sets the rendering key of an element.
  • WithRegistered - Registeres values for its child. Intended to be used in combination with self.context.registered(...).

  • HTMLVoidElement - long form of VEl, pass tag: str, attributes: dict[str, str | CustomAttribute | None] to the constructor

  • HTMLElement - long form of El, pass tag: str, attributes: dict[str, str | CustomAttribute | None] = {}, content: Iterable[Element | str] = (), key: str | None = None to the constructor
  • class_map - Turn a dict[str, bool] into a space separated class string.
  • merge_attributes - Merge two attribute dictionaries, normalizing keys and joining class / style values.
  • add_attributes - Convenience wrapper to extend an attribute dict with keyword arguments via merge_attributes.