nakai/html

Types

pub type Node {
  Doctype(content: String)
  Html(attrs: List(Attr), children: List(Node))
  Head(children: List(Node))
  Body(attrs: List(Attr), children: List(Node))
  Fragment(children: List(Node))
  Element(tag: String, attrs: List(Attr), children: List(Node))
  LeafElement(tag: String, attrs: List(Attr))
  Comment(content: String)
  Text(content: String)
  UnsafeInlineHtml(content: String)
  Script(script: String)
  Nothing
}

Constructors

  • Doctype(content: String)

    Can be used anywhere in the document, and will set the doctype of the document being rendered. Usually not necessary, as documents have a default of <!DOCTYPE html>.

    Example

    html.Doctype("html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\"")
    
  • Html(attrs: List(Attr), children: List(Node))

    Used for setting attributes on the root <html> element of the document. Children will be rendered in-place, equivalent to using html.Fragment(children).

    Example

    html.Html([attrs.lang("en-US")], [
      ...
    ])
    
  • Head(children: List(Node))

    Used for placing content in the <head> of the document. Useful for elements like <meta>, <title>, <link>, etc.

    Example

    html.Fragment([
      html.Head([
        html.title("List of puppies")
      ]),
      html.div([], [
        ...
      ])
    ])
    
  • Body(attrs: List(Attr), children: List(Node))

    Used for setting attributes on the <body> element of the document. Children will be rendered in-place, equivalent to using html.Fragment(children).

    Example

    html.Body([attrs.class("dark-mode")], [
      ...
    ])
    
  • Fragment(children: List(Node))

    An “transparent” container that will render it’s children, but does not add anything itself to the document. If you’ve ever used React.Fragment or <> and </> in JSX/React, this is that.

    Example

    html.ul([], [
      // some puppies are hard-coded
      html.li_text([], "August"),
      // some are loaded from a server
      html.Fragment(puppies_fetched_from_api |> list.map(html.li_text([], _)))
    ])
    // <ul>
    //   <li>August</li>
    //   <li>Dot</li>
    //   <li>Mody</li>
    //   <li>Spot</li>
    //   <li>Toby</li>
    // </ul>
    
  • Element(tag: String, attrs: List(Attr), children: List(Node))

    An HTML element. You shouldn’t need to reach for this very often, but it can be a handy escape hatch if there isn’t a shorthand function for the element type you need.

    Example

    // bad example, pls use `html.div`
    html.Element("div", [], [html.Text("hello, lucy!")])
    
  • LeafElement(tag: String, attrs: List(Attr))

    An HTML element, but that does not have any children, and should be self closing. Similarly to Element, you shouldn’t really need this, except as an escape hatch if there isn’t a shorthand function for the element type you need.

    Example

    // bad example, pls use `html.link`
    html.LeafElement("link", [attrs.rel("stylesheet"), attrs.href(...)])
    
  • Comment(content: String)

    An HTML comment, which will be included in the document.

    Example

    html.Comment("You've uncovered my secrets!")
    // <!-- You've uncovered my secrets! -->
    
  • Text(content: String)

    Some plain text to include in the document. The provided text will be escaped, to make it safe to include in the document.

    Example

    html.Text("hello, lucy!")
    // hello, lucy!
    
    // Time to trust some unvalidated user input! :^)
    html.div_text([], "<script>alert('pwned');</script>")
    // <div>&lt;script&gt;alert('pwned');&lt;/script&gt;</div>
    
  • UnsafeInlineHtml(content: String)

    The dangerous cousin of Text. This will render the provided text as-is, without any santization. Good for things like including some HTML you just generated from a Markdown file. Bad for things like $_GET['search'].

    Example

    html.Text("hello, lucy!")
    // hello, lucy!
    
    // Time to trust some unvalidated user input! :^)
    html.div([], [html.UnsafeInlineHtml("<script>alert('pwned');</script>")])
    // <div><script>alert('pwned');</script></div>
    // Oh no, we just got got! D:
    
  • Script(script: String)

    Add some JavaScript to your page! Scripts will always be inserted at the end of the page, regardless of where in the document the Script node is, so that your content loads first.

    Example

    html.Script("alert('hello, lucy!')")
    
  • Nothing

    Renders absolutely nothing. For when you may or may not have something to render, and need a way to say “I’ve got nothing.”

    Example

    html.div([], [
      case my_cool_feature {
        Enabled -> super_cool_stuff()
        Disabled -> html.Nothing
      }
    ])

Functions

pub fn a(attrs: List(Attr), children: List(Node)) -> Node
pub fn a_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.a(attrs, children: [html.Text(text)])

pub fn abbr(attrs: List(Attr), children: List(Node)) -> Node
pub fn abbr_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.abbr(attrs, children: [html.Text(text)])

pub fn address(attrs: List(Attr), children: List(Node)) -> Node
pub fn address_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.address(attrs, children: [html.Text(text)])

pub fn area(attrs: List(Attr)) -> Node
pub fn article(attrs: List(Attr), children: List(Node)) -> Node
pub fn article_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.article(attrs, children: [html.Text(text)])

pub fn aside(attrs: List(Attr), children: List(Node)) -> Node
pub fn aside_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.aside(attrs, children: [html.Text(text)])

pub fn audio(attrs: List(Attr), children: List(Node)) -> Node
pub fn audio_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.audio(attrs, children: [html.Text(text)])

pub fn b(attrs: List(Attr), children: List(Node)) -> Node
pub fn b_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.b(attrs, children: [html.Text(text)])

pub fn base(attrs: List(Attr)) -> Node
pub fn bdi(attrs: List(Attr), children: List(Node)) -> Node
pub fn bdi_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.bdi(attrs, children: [html.Text(text)])

pub fn bdo(attrs: List(Attr), children: List(Node)) -> Node
pub fn bdo_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.bdo(attrs, children: [html.Text(text)])

pub fn blockquote(
  attrs: List(Attr),
  children: List(Node),
) -> Node
pub fn blockquote_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.blockquote(attrs, children: [html.Text(text)])

pub fn br(attrs: List(Attr)) -> Node
pub fn button(attrs: List(Attr), children: List(Node)) -> Node
pub fn button_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.button(attrs, children: [html.Text(text)])

pub fn canvas(attrs: List(Attr), children: List(Node)) -> Node
pub fn canvas_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.canvas(attrs, children: [html.Text(text)])

pub fn caption(attrs: List(Attr), children: List(Node)) -> Node
pub fn caption_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.caption(attrs, children: [html.Text(text)])

pub fn cite(attrs: List(Attr), children: List(Node)) -> Node
pub fn cite_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.cite(attrs, children: [html.Text(text)])

pub fn code(attrs: List(Attr), children: List(Node)) -> Node
pub fn code_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.code(attrs, children: [html.Text(text)])

pub fn col(attrs: List(Attr), children: List(Node)) -> Node
pub fn col_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.col(attrs, children: [html.Text(text)])

pub fn colgroup(attrs: List(Attr), children: List(Node)) -> Node
pub fn colgroup_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.colgroup(attrs, children: [html.Text(text)])

pub fn data(attrs: List(Attr), children: List(Node)) -> Node
pub fn data_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.data(attrs, children: [html.Text(text)])

pub fn datalist(attrs: List(Attr), children: List(Node)) -> Node
pub fn datalist_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.datalist(attrs, children: [html.Text(text)])

pub fn dd(attrs: List(Attr), children: List(Node)) -> Node
pub fn dd_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.dd(attrs, children: [html.Text(text)])

pub fn del(attrs: List(Attr), children: List(Node)) -> Node
pub fn del_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.del(attrs, children: [html.Text(text)])

pub fn details(attrs: List(Attr), children: List(Node)) -> Node
pub fn details_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.details(attrs, children: [html.Text(text)])

pub fn dfn(attrs: List(Attr), children: List(Node)) -> Node
pub fn dfn_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.dfn(attrs, children: [html.Text(text)])

pub fn dialog(attrs: List(Attr), children: List(Node)) -> Node
pub fn dialog_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.dialog(attrs, children: [html.Text(text)])

pub fn div(attrs: List(Attr), children: List(Node)) -> Node
pub fn div_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.div(attrs, children: [html.Text(text)])

pub fn dl(attrs: List(Attr), children: List(Node)) -> Node
pub fn dl_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.dl(attrs, children: [html.Text(text)])

pub fn dt(attrs: List(Attr), children: List(Node)) -> Node
pub fn dt_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.dt(attrs, children: [html.Text(text)])

pub fn em(attrs: List(Attr), children: List(Node)) -> Node
pub fn em_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.em(attrs, children: [html.Text(text)])

pub fn embed(attrs: List(Attr), children: List(Node)) -> Node
pub fn embed_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.embed(attrs, children: [html.Text(text)])

pub fn fieldset(attrs: List(Attr), children: List(Node)) -> Node
pub fn fieldset_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.fieldset(attrs, children: [html.Text(text)])

pub fn figcaption(
  attrs: List(Attr),
  children: List(Node),
) -> Node
pub fn figcaption_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.figcaption(attrs, children: [html.Text(text)])

pub fn figure(attrs: List(Attr), children: List(Node)) -> Node
pub fn figure_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.figure(attrs, children: [html.Text(text)])

pub fn footer(attrs: List(Attr), children: List(Node)) -> Node
pub fn footer_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.footer(attrs, children: [html.Text(text)])

pub fn form(attrs: List(Attr), children: List(Node)) -> Node
pub fn form_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.form(attrs, children: [html.Text(text)])

pub fn h1(attrs: List(Attr), children: List(Node)) -> Node
pub fn h1_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.h1(attrs, children: [html.Text(text)])

pub fn h2(attrs: List(Attr), children: List(Node)) -> Node
pub fn h2_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.h2(attrs, children: [html.Text(text)])

pub fn h3(attrs: List(Attr), children: List(Node)) -> Node
pub fn h3_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.h3(attrs, children: [html.Text(text)])

pub fn h4(attrs: List(Attr), children: List(Node)) -> Node
pub fn h4_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.h4(attrs, children: [html.Text(text)])

pub fn h5(attrs: List(Attr), children: List(Node)) -> Node
pub fn h5_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.h5(attrs, children: [html.Text(text)])

pub fn h6(attrs: List(Attr), children: List(Node)) -> Node
pub fn h6_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.h6(attrs, children: [html.Text(text)])

pub fn header(attrs: List(Attr), children: List(Node)) -> Node
pub fn header_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.header(attrs, children: [html.Text(text)])

pub fn hr(attrs: List(Attr)) -> Node
pub fn i(attrs: List(Attr), children: List(Node)) -> Node
pub fn i_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.i(attrs, children: [html.Text(text)])

pub fn iframe(attrs: List(Attr), children: List(Node)) -> Node
pub fn iframe_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.iframe(attrs, children: [html.Text(text)])

pub fn img(attrs: List(Attr)) -> Node
pub fn input(attrs: List(Attr)) -> Node
pub fn ins(attrs: List(Attr), children: List(Node)) -> Node
pub fn ins_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.ins(attrs, children: [html.Text(text)])

pub fn kbd(attrs: List(Attr), children: List(Node)) -> Node
pub fn kbd_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.kbd(attrs, children: [html.Text(text)])

pub fn label(attrs: List(Attr), children: List(Node)) -> Node
pub fn label_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.label(attrs, children: [html.Text(text)])

pub fn legend(attrs: List(Attr), children: List(Node)) -> Node
pub fn legend_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.legend(attrs, children: [html.Text(text)])

pub fn li(attrs: List(Attr), children: List(Node)) -> Node
pub fn li_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.li(attrs, children: [html.Text(text)])

pub fn link(attrs: List(Attr)) -> Node
pub fn main(attrs: List(Attr), children: List(Node)) -> Node
pub fn main_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.main(attrs, children: [html.Text(text)])

pub fn map(attrs: List(Attr), children: List(Node)) -> Node
pub fn map_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.map(attrs, children: [html.Text(text)])

pub fn mark(attrs: List(Attr), children: List(Node)) -> Node
pub fn mark_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.mark(attrs, children: [html.Text(text)])

pub fn math(attrs: List(Attr), children: List(Node)) -> Node
pub fn math_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.math(attrs, children: [html.Text(text)])

pub fn menu(attrs: List(Attr), children: List(Node)) -> Node
pub fn menu_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.menu(attrs, children: [html.Text(text)])

pub fn menuitem(attrs: List(Attr), children: List(Node)) -> Node
pub fn menuitem_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.menuitem(attrs, children: [html.Text(text)])

pub fn meta(attrs: List(Attr)) -> Node
pub fn meter(attrs: List(Attr), children: List(Node)) -> Node
pub fn meter_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.meter(attrs, children: [html.Text(text)])

pub fn nav(attrs: List(Attr), children: List(Node)) -> Node
pub fn nav_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.nav(attrs, children: [html.Text(text)])

pub fn noscript(attrs: List(Attr), children: List(Node)) -> Node
pub fn noscript_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.noscript(attrs, children: [html.Text(text)])

pub fn object(attrs: List(Attr), children: List(Node)) -> Node
pub fn object_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.object(attrs, children: [html.Text(text)])

pub fn ol(attrs: List(Attr), children: List(Node)) -> Node
pub fn ol_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.ol(attrs, children: [html.Text(text)])

pub fn optgroup(attrs: List(Attr), children: List(Node)) -> Node
pub fn optgroup_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.optgroup(attrs, children: [html.Text(text)])

pub fn option(attrs: List(Attr), children: List(Node)) -> Node
pub fn option_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.option(attrs, children: [html.Text(text)])

pub fn output(attrs: List(Attr), children: List(Node)) -> Node
pub fn output_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.output(attrs, children: [html.Text(text)])

pub fn p(attrs: List(Attr), children: List(Node)) -> Node
pub fn p_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.p(attrs, children: [html.Text(text)])

pub fn param(attrs: List(Attr), children: List(Node)) -> Node
pub fn param_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.param(attrs, children: [html.Text(text)])

pub fn picture(attrs: List(Attr), children: List(Node)) -> Node
pub fn picture_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.picture(attrs, children: [html.Text(text)])

pub fn pre(attrs: List(Attr), children: List(Node)) -> Node
pub fn pre_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.pre(attrs, children: [html.Text(text)])

pub fn progress(attrs: List(Attr), children: List(Node)) -> Node
pub fn progress_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.progress(attrs, children: [html.Text(text)])

pub fn q(attrs: List(Attr), children: List(Node)) -> Node
pub fn q_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.q(attrs, children: [html.Text(text)])

pub fn rp(attrs: List(Attr), children: List(Node)) -> Node
pub fn rp_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.rp(attrs, children: [html.Text(text)])

pub fn rt(attrs: List(Attr), children: List(Node)) -> Node
pub fn rt_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.rt(attrs, children: [html.Text(text)])

pub fn ruby(attrs: List(Attr), children: List(Node)) -> Node
pub fn ruby_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.ruby(attrs, children: [html.Text(text)])

pub fn s(attrs: List(Attr), children: List(Node)) -> Node
pub fn s_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.s(attrs, children: [html.Text(text)])

pub fn samp(attrs: List(Attr), children: List(Node)) -> Node
pub fn samp_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.samp(attrs, children: [html.Text(text)])

pub fn section(attrs: List(Attr), children: List(Node)) -> Node
pub fn section_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.section(attrs, children: [html.Text(text)])

pub fn select(attrs: List(Attr), children: List(Node)) -> Node
pub fn select_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.select(attrs, children: [html.Text(text)])

pub fn small(attrs: List(Attr), children: List(Node)) -> Node
pub fn small_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.small(attrs, children: [html.Text(text)])

pub fn source(attrs: List(Attr)) -> Node
pub fn span(attrs: List(Attr), children: List(Node)) -> Node
pub fn span_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.span(attrs, children: [html.Text(text)])

pub fn strong(attrs: List(Attr), children: List(Node)) -> Node
pub fn strong_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.strong(attrs, children: [html.Text(text)])

pub fn sub(attrs: List(Attr), children: List(Node)) -> Node
pub fn sub_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.sub(attrs, children: [html.Text(text)])

pub fn summary(attrs: List(Attr), children: List(Node)) -> Node
pub fn summary_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.summary(attrs, children: [html.Text(text)])

pub fn sup(attrs: List(Attr), children: List(Node)) -> Node
pub fn sup_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.sup(attrs, children: [html.Text(text)])

pub fn svg(attrs: List(Attr), children: List(Node)) -> Node
pub fn svg_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.svg(attrs, children: [html.Text(text)])

pub fn table(attrs: List(Attr), children: List(Node)) -> Node
pub fn table_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.table(attrs, children: [html.Text(text)])

pub fn tbody(attrs: List(Attr), children: List(Node)) -> Node
pub fn tbody_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.tbody(attrs, children: [html.Text(text)])

pub fn td(attrs: List(Attr), children: List(Node)) -> Node
pub fn td_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.td(attrs, children: [html.Text(text)])

pub fn textarea(attrs: List(Attr), children: List(Node)) -> Node
pub fn textarea_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.textarea(attrs, children: [html.Text(text)])

pub fn tfoot(attrs: List(Attr), children: List(Node)) -> Node
pub fn tfoot_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.tfoot(attrs, children: [html.Text(text)])

pub fn th(attrs: List(Attr), children: List(Node)) -> Node
pub fn th_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.th(attrs, children: [html.Text(text)])

pub fn thead(attrs: List(Attr), children: List(Node)) -> Node
pub fn thead_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.thead(attrs, children: [html.Text(text)])

pub fn time(attrs: List(Attr), children: List(Node)) -> Node
pub fn time_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.time(attrs, children: [html.Text(text)])

pub fn title(text: String) -> Node

The HTML <title> element

pub fn tr(attrs: List(Attr), children: List(Node)) -> Node
pub fn tr_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.tr(attrs, children: [html.Text(text)])

pub fn track(attrs: List(Attr)) -> Node
pub fn u(attrs: List(Attr), children: List(Node)) -> Node
pub fn u_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.u(attrs, children: [html.Text(text)])

pub fn ul(attrs: List(Attr), children: List(Node)) -> Node
pub fn ul_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.ul(attrs, children: [html.Text(text)])

pub fn var(attrs: List(Attr), children: List(Node)) -> Node
pub fn var_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.var(attrs, children: [html.Text(text)])

pub fn video(attrs: List(Attr), children: List(Node)) -> Node
pub fn video_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.video(attrs, children: [html.Text(text)])

pub fn wbr(attrs: List(Attr), children: List(Node)) -> Node
pub fn wbr_text(attrs: List(Attr), text: String) -> Node

Shorthand for html.wbr(attrs, children: [html.Text(text)])

Search Document