espresso/html

Experimental module used to render functions into an io list and turn that list into a string

This module is experimental and may change or be removed

Types

pub type Attributes =
  List(#(String, String))
pub type Element {
  Text(text: String)
  Element(
    tag_name: String,
    attributes: Attributes,
    children: Children,
  )
  Raw(text: String)
}

Constructors

  • Text(text: String)
  • Element(
      tag_name: String,
      attributes: Attributes,
      children: Children,
    )
  • Raw(text: String)

Functions

pub fn a(el: Element, name: String, value: String) -> Element

Adds an attribute of name+value to an HTML element

pub fn c(el: Element, new_children: List(Element)) -> Element

Adds children to an element

pub fn doctype() -> StringBuilder
pub fn dyn(el: Element, dyn: a) -> Element
pub fn escape(acc: StringBuilder, text: String) -> StringBuilder
pub fn new(tag_name: String, attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn raw(text: String) -> Element
pub fn render(element: Element) -> StringBuilder
pub fn t(name: String) -> Element

Creates a new HTML element with the given tag name

pub fn to_string(dom: Element) -> String

Renders an HTML element into a string of HTML

Examples

pub fn txt(text: String) -> Element

Adds a text node to an element

Search Document