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,
  )
}

Constructors

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

Functions

pub fn a(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn abbr(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn address(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn area(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn article(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn aside(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn audio(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn b(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn base(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn bdi(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn blockquote(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn body(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn br(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn canvas(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn caption(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn cite(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn code(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn col(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn colgroup(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn data(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn datalist(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn dd(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn del(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn details(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn dialog(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn div(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn doctype() -> StringBuilder
pub fn em(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn h1(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn h2(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn h3(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn h4(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn h5(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn h6(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn head(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn hr(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn html(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn img(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn li(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn link(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn meta(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn ol(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn p(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn pre(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn render(element: Element) -> StringBuilder
pub fn script(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn section(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn span(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn style(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn table(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn tbody(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn td(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn text(text: String) -> Element
pub fn th(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn thead(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn title(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn to_string(dom: Element) -> String

Renders an HTML element into a string of HTML

Examples

 html(
   [#("lang", "en")],
   [
     head(
       [],
       [
         meta(
           [
             #("name", "viewport"),
             #("content", "width=device-width, initial-scale=1"),
           ],
           [],
         ),
         title([], [text("Rendered with espresso HTML")]),
         link(
           [
             #("rel", "stylesheet"),
             #("href", "https://fonts.googleapis.com/css?family=Tangerine"),
           ],
           [],
         ),
         style(
           [],
           [
             text(
               "
               body { 
                 font-family: 'Tangerine', serif; font-size: 48px;
               }
               ",
             ),
           ],
         ),
       ],
     ),
     body([], [div([], [text("Hello")])]),
   ],
 )
 |> to_string()
pub fn tr(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
pub fn ul(attributes: List(#(String, String)), children: List(
    Element,
  )) -> Element
Search Document