builder.html.Document
class pub Document
A container for HTML nodes
A Document
defaults to being treated as a whole HTML5 document (i.e. with a
doctype), but this can be disabled by setting Document.fragment
to true
.
Fields
nodes
let pub @nodes: Array[Node]
All top-level nodes in this document.
Static methods
fragment
Show source codeHide source code
fn pub static fragment -> Document {
Document(nodes: [], doctype: false)
}
fn pub static fragment -> Document
Returns a new empty document that acts as a fragment.
A fragment is an HTML document without a doctype, making it useful for generating chunks of HTML meant to be included in other chunks of HTML (e.g. when rendering Markdown as part of a larger document).
Examples
import builder.html.Document
let doc = Document.fragment
doc.to_string # => ''
html
Show source codeHide source code
fn pub static html(lang: String, func: fn (mut Element)) -> Document {
let doc = new
doc.element('html').attr('lang', lang).with(func)
doc
}
fn pub static html(lang: String, func: fn (mut Element)) -> Document
Returns a Document
that containes a top-level <html>
tag.
The lang
argument specifies the value of the lang
attribute of the
<html>
element.
The func
argument is called with a mutable reference to the top-level
<html>
element.
Examples
import builder.html.Document
Document.html('en', fn (html) {
html.head.title.text('Hello')
})
new
Show source codeHide source code
fn pub static new -> Document {
Document(nodes: [], doctype: true)
}
fn pub static new -> Document
Returns a new empty document.
Examples
import builder.html.Document
let doc = Document.new
doc.to_string # => '<!DOCTYPE html>'
Instance methods
a
Show source codeHide source code
fn pub mut a -> mut Element {
element('a').inline
}
fn pub mut a -> mut Element
Adds a <a>
element as a child element.
abbr
Show source codeHide source code
fn pub mut abbr -> mut Element {
element('abbr').inline
}
fn pub mut abbr -> mut Element
Adds a <abbr>
element as a child element.
add
Show source codeHide source code
fn pub mut add(element: Element) {
nodes_mut.push(Node.Element(element))
}
fn pub mut add(element: Element)
Adds the child Element
to self
.
Examples
import builder.html.Element
Element.new('p').add(Element.new('span'))
address
Show source codeHide source code
fn pub mut address -> mut Element {
element('address').inline
}
fn pub mut address -> mut Element
Adds a <address>
element as a child element.
append
Show source codeHide source code
fn pub mut append(document: Document) {
match document {
case { @nodes = n } -> nodes_mut.append(n)
}
}
fn pub mut append(document: Document)
Adds the nodes of the given Document
to self
.
Examples
import builder.html.(Document, Element)
let doc1 = Document.fragment
let doc2 = Document.fragment
doc1.p.text('test')
doc2.div.append(doc1)
doc2.to_string # => '<div><p>test</p></div>'
area
Show source codeHide source code
fn pub mut area -> mut Element {
element('area').self_closing.inline
}
fn pub mut area -> mut Element
Adds a <area>
element as a child element.
article
Show source codeHide source code
fn pub mut article -> mut Element {
element('article')
}
fn pub mut article -> mut Element
Adds a <article>
element as a child element.
aside
Show source codeHide source code
fn pub mut aside -> mut Element {
element('aside')
}
fn pub mut aside -> mut Element
Adds a <aside>
element as a child element.
audio
Show source codeHide source code
fn pub mut audio -> mut Element {
element('audio').inline
}
fn pub mut audio -> mut Element
Adds a <audio>
element as a child element.
b
Show source codeHide source code
fn pub mut b -> mut Element {
element('b').inline
}
fn pub mut b -> mut Element
Adds a <b>
element as a child element.
base
Show source codeHide source code
fn pub mut base -> mut Element {
element('base').self_closing
}
fn pub mut base -> mut Element
Adds a <base>
element as a child element.
bdi
Show source codeHide source code
fn pub mut bdi -> mut Element {
element('bdi')
}
fn pub mut bdi -> mut Element
Adds a <bdi>
element as a child element.
bdo
Show source codeHide source code
fn pub mut bdo -> mut Element {
element('bdo')
}
fn pub mut bdo -> mut Element
Adds a <bdo>
element as a child element.
blockquote
Show source codeHide source code
fn pub mut blockquote -> mut Element {
element('blockquote')
}
fn pub mut blockquote -> mut Element
Adds a <blockquote>
element as a child element.
body
Show source codeHide source code
fn pub mut body -> mut Element {
element('body')
}
fn pub mut body -> mut Element
Adds a <body>
element as a child element.
br
Show source codeHide source code
fn pub mut br -> mut Element {
element('br').self_closing
}
fn pub mut br -> mut Element
Adds a <br>
element as a child element.
button
Show source codeHide source code
fn pub mut button -> mut Element {
element('button')
}
fn pub mut button -> mut Element
Adds a <button>
element as a child element.
canvas
Show source codeHide source code
fn pub mut canvas -> mut Element {
element('canvas')
}
fn pub mut canvas -> mut Element
Adds a <canvas>
element as a child element.
caption
Show source codeHide source code
fn pub mut caption -> mut Element {
element('caption')
}
fn pub mut caption -> mut Element
Adds a <caption>
element as a child element.
cite
Show source codeHide source code
fn pub mut cite -> mut Element {
element('cite').inline
}
fn pub mut cite -> mut Element
Adds a <cite>
element as a child element.
code
Show source codeHide source code
fn pub mut code -> mut Element {
element('code').inline
}
fn pub mut code -> mut Element
Adds a <code>
element as a child element.
col
Show source codeHide source code
fn pub mut col -> mut Element {
element('col').self_closing
}
fn pub mut col -> mut Element
Adds a <col>
element as a child element.
colgroup
Show source codeHide source code
fn pub mut colgroup -> mut Element {
element('colgroup')
}
fn pub mut colgroup -> mut Element
Adds a <colgroup>
element as a child element.
data
Show source codeHide source code
fn pub mut data -> mut Element {
element('data')
}
fn pub mut data -> mut Element
Adds a <data>
element as a child element.
datalist
Show source codeHide source code
fn pub mut datalist -> mut Element {
element('datalist')
}
fn pub mut datalist -> mut Element
Adds a <datalist>
element as a child element.
dd
Show source codeHide source code
fn pub mut dd -> mut Element {
element('dd')
}
fn pub mut dd -> mut Element
Adds a <dd>
element as a child element.
del
Show source codeHide source code
fn pub mut del -> mut Element {
element('del').inline
}
fn pub mut del -> mut Element
Adds a <del>
element as a child element.
details
Show source codeHide source code
fn pub mut details -> mut Element {
element('details')
}
fn pub mut details -> mut Element
Adds a <details>
element as a child element.
dfn
Show source codeHide source code
fn pub mut dfn -> mut Element {
element('dfn').inline
}
fn pub mut dfn -> mut Element
Adds a <dfn>
element as a child element.
dialog
Show source codeHide source code
fn pub mut dialog -> mut Element {
element('dialog')
}
fn pub mut dialog -> mut Element
Adds a <dialog>
element as a child element.
div
Show source codeHide source code
fn pub mut div -> mut Element {
element('div')
}
fn pub mut div -> mut Element
Adds a <div>
element as a child element.
dl
Show source codeHide source code
fn pub mut dl -> mut Element {
element('dl')
}
fn pub mut dl -> mut Element
Adds a <dl>
element as a child element.
dt
Show source codeHide source code
fn pub mut dt -> mut Element {
element('dt')
}
fn pub mut dt -> mut Element
Adds a <dt>
element as a child element.
element
Show source codeHide source code
fn pub mut element(name: String) -> mut Element {
let el = Element.new(name)
let ret = mut el
add(el)
ret
}
fn pub mut element(name: String) -> mut Element
Adds an element with the given name as a cild of self
.
em
Show source codeHide source code
fn pub mut em -> mut Element {
element('em').inline
}
fn pub mut em -> mut Element
Adds a <em>
element as a child element.
embed
Show source codeHide source code
fn pub mut embed -> mut Element {
element('embed').self_closing
}
fn pub mut embed -> mut Element
Adds a <embed>
element as a child element.
fieldset
Show source codeHide source code
fn pub mut fieldset -> mut Element {
element('fieldset')
}
fn pub mut fieldset -> mut Element
Adds a <fieldset>
element as a child element.
figcaption
Show source codeHide source code
fn pub mut figcaption -> mut Element {
element('figcaption')
}
fn pub mut figcaption -> mut Element
Adds a <figcaption>
element as a child element.
figure
Show source codeHide source code
fn pub mut figure -> mut Element {
element('figure')
}
fn pub mut figure -> mut Element
Adds a <figure>
element as a child element.
footer
Show source codeHide source code
fn pub mut footer -> mut Element {
element('footer')
}
fn pub mut footer -> mut Element
Adds a <footer>
element as a child element.
form
Show source codeHide source code
fn pub mut form -> mut Element {
element('form')
}
fn pub mut form -> mut Element
Adds a <form>
element as a child element.
h1
Show source codeHide source code
fn pub mut h1 -> mut Element {
element('h1')
}
fn pub mut h1 -> mut Element
Adds a <h1>
element as a child element.
h2
Show source codeHide source code
fn pub mut h2 -> mut Element {
element('h2')
}
fn pub mut h2 -> mut Element
Adds a <h2>
element as a child element.
h3
Show source codeHide source code
fn pub mut h3 -> mut Element {
element('h3')
}
fn pub mut h3 -> mut Element
Adds a <h3>
element as a child element.
h4
Show source codeHide source code
fn pub mut h4 -> mut Element {
element('h4')
}
fn pub mut h4 -> mut Element
Adds a <h4>
element as a child element.
h5
Show source codeHide source code
fn pub mut h5 -> mut Element {
element('h5')
}
fn pub mut h5 -> mut Element
Adds a <h5>
element as a child element.
h6
Show source codeHide source code
fn pub mut h6 -> mut Element {
element('h6')
}
fn pub mut h6 -> mut Element
Adds a <h6>
element as a child element.
head
Show source codeHide source code
fn pub mut head -> mut Element {
element('head')
}
fn pub mut head -> mut Element
Adds a <head>
element as a child element.
header
Show source codeHide source code
fn pub mut header -> mut Element {
element('header')
}
fn pub mut header -> mut Element
Adds a <header>
element as a child element.
hgroup
Show source codeHide source code
fn pub mut hgroup -> mut Element {
element('hgroup')
}
fn pub mut hgroup -> mut Element
Adds a <hgroup>
element as a child element.
hr
Show source codeHide source code
fn pub mut hr -> mut Element {
element('hr').self_closing
}
fn pub mut hr -> mut Element
Adds a <hr>
element as a child element.
i
Show source codeHide source code
fn pub mut i -> mut Element {
element('i').inline
}
fn pub mut i -> mut Element
Adds a <i>
element as a child element.
iframe
Show source codeHide source code
fn pub mut iframe -> mut Element {
element('iframe')
}
fn pub mut iframe -> mut Element
Adds a <iframe>
element as a child element.
img
Show source codeHide source code
fn pub mut img -> mut Element {
element('img').self_closing.inline
}
fn pub mut img -> mut Element
Adds a <img>
element as a child element.
input
Show source codeHide source code
fn pub mut input -> mut Element {
element('input').self_closing
}
fn pub mut input -> mut Element
Adds a <input>
element as a child element.
ins
Show source codeHide source code
fn pub mut ins -> mut Element {
element('ins').inline
}
fn pub mut ins -> mut Element
Adds a <ins>
element as a child element.
kbd
Show source codeHide source code
fn pub mut kbd -> mut Element {
element('kbd').inline
}
fn pub mut kbd -> mut Element
Adds a <kbd>
element as a child element.
label
Show source codeHide source code
fn pub mut label -> mut Element {
element('label')
}
fn pub mut label -> mut Element
Adds a <label>
element as a child element.
legend
Show source codeHide source code
fn pub mut legend -> mut Element {
element('legend').inline
}
fn pub mut legend -> mut Element
Adds a <legend>
element as a child element.
li
Show source codeHide source code
fn pub mut li -> mut Element {
element('li')
}
fn pub mut li -> mut Element
Adds a <li>
element as a child element.
link
Show source codeHide source code
fn pub mut link -> mut Element {
element('link').self_closing
}
fn pub mut link -> mut Element
Adds a <link>
element as a child element.
main
Show source codeHide source code
fn pub mut main -> mut Element {
element('main')
}
fn pub mut main -> mut Element
Adds a <main>
element as a child element.
map
Show source codeHide source code
fn pub mut map -> mut Element {
element('map')
}
fn pub mut map -> mut Element
Adds a <map>
element as a child element.
mark
Show source codeHide source code
fn pub mut mark -> mut Element {
element('mark').inline
}
fn pub mut mark -> mut Element
Adds a <mark>
element as a child element.
menu
Show source codeHide source code
fn pub mut menu -> mut Element {
element('menu')
}
fn pub mut menu -> mut Element
Adds a <menu>
element as a child element.
meta
Show source codeHide source code
fn pub mut meta -> mut Element {
element('meta').self_closing
}
fn pub mut meta -> mut Element
Adds a <meta>
element as a child element.
meter
Show source codeHide source code
fn pub mut meter -> mut Element {
element('meter').inline
}
fn pub mut meter -> mut Element
Adds a <meter>
element as a child element.
nav
Show source codeHide source code
fn pub mut nav -> mut Element {
element('nav')
}
fn pub mut nav -> mut Element
Adds a <nav>
element as a child element.
nodes_mut
Show source codeHide source code
fn pub mut nodes_mut -> mut Array[Node] {
@nodes
}
fn pub mut nodes_mut -> mut Array[Node]
Returns a mutable reference to the nodes of self
.
noscript
Show source codeHide source code
fn pub mut noscript -> mut Element {
element('noscript')
}
fn pub mut noscript -> mut Element
Adds a <noscript>
element as a child element.
object
Show source codeHide source code
fn pub mut object -> mut Element {
element('object')
}
fn pub mut object -> mut Element
Adds a <object>
element as a child element.
ol
Show source codeHide source code
fn pub mut ol -> mut Element {
element('ol')
}
fn pub mut ol -> mut Element
Adds a <ol>
element as a child element.
optgroup
Show source codeHide source code
fn pub mut optgroup -> mut Element {
element('optgroup')
}
fn pub mut optgroup -> mut Element
Adds a <optgroup>
element as a child element.
option
Show source codeHide source code
fn pub mut option -> mut Element {
element('option')
}
fn pub mut option -> mut Element
Adds a <option>
element as a child element.
output
Show source codeHide source code
fn pub mut output -> mut Element {
element('output')
}
fn pub mut output -> mut Element
Adds a <output>
element as a child element.
p
Show source codeHide source code
fn pub mut p -> mut Element {
element('p')
}
fn pub mut p -> mut Element
Adds a <p>
element as a child element.
picture
Show source codeHide source code
fn pub mut picture -> mut Element {
element('picture')
}
fn pub mut picture -> mut Element
Adds a <picture>
element as a child element.
portal
Show source codeHide source code
fn pub mut portal -> mut Element {
element('portal')
}
fn pub mut portal -> mut Element
Adds a <portal>
element as a child element.
pre
Show source codeHide source code
fn pub mut pre -> mut Element {
element('pre')
}
fn pub mut pre -> mut Element
Adds a <pre>
element as a child element.
progress
Show source codeHide source code
fn pub mut progress -> mut Element {
element('progress')
}
fn pub mut progress -> mut Element
Adds a <progress>
element as a child element.
q
Show source codeHide source code
fn pub mut q -> mut Element {
element('q').inline
}
fn pub mut q -> mut Element
Adds a <q>
element as a child element.
rp
Show source codeHide source code
fn pub mut rp -> mut Element {
element('rp')
}
fn pub mut rp -> mut Element
Adds a <rp>
element as a child element.
rt
Show source codeHide source code
fn pub mut rt -> mut Element {
element('rt')
}
fn pub mut rt -> mut Element
Adds a <rt>
element as a child element.
ruby
Show source codeHide source code
fn pub mut ruby -> mut Element {
element('ruby')
}
fn pub mut ruby -> mut Element
Adds a <ruby>
element as a child element.
s
Show source codeHide source code
fn pub mut s -> mut Element {
element('s')
}
fn pub mut s -> mut Element
Adds a <s>
element as a child element.
samp
Show source codeHide source code
fn pub mut samp -> mut Element {
element('samp')
}
fn pub mut samp -> mut Element
Adds a <samp>
element as a child element.
script
Show source codeHide source code
fn pub mut script -> mut Element {
element('script')
}
fn pub mut script -> mut Element
Adds a <script>
element as a child element.
search
Show source codeHide source code
fn pub mut search -> mut Element {
element('search')
}
fn pub mut search -> mut Element
Adds a <search>
element as a child element.
section
Show source codeHide source code
fn pub mut section -> mut Element {
element('section')
}
fn pub mut section -> mut Element
Adds a <section>
element as a child element.
select
Show source codeHide source code
fn pub mut select -> mut Element {
element('select')
}
fn pub mut select -> mut Element
Adds a <select>
element as a child element.
slot
Show source codeHide source code
fn pub mut slot -> mut Element {
element('slot')
}
fn pub mut slot -> mut Element
Adds a <slot>
element as a child element.
small
Show source codeHide source code
fn pub mut small -> mut Element {
element('small').inline
}
fn pub mut small -> mut Element
Adds a <small>
element as a child element.
source
Show source codeHide source code
fn pub mut source -> mut Element {
element('source').self_closing.inline
}
fn pub mut source -> mut Element
Adds a <source>
element as a child element.
span
Show source codeHide source code
fn pub mut span -> mut Element {
element('span').inline
}
fn pub mut span -> mut Element
Adds a <span>
element as a child element.
strong
Show source codeHide source code
fn pub mut strong -> mut Element {
element('strong').inline
}
fn pub mut strong -> mut Element
Adds a <strong>
element as a child element.
style
Show source codeHide source code
fn pub mut style -> mut Element {
element('style')
}
fn pub mut style -> mut Element
Adds a <style>
element as a child element.
sub
Show source codeHide source code
fn pub mut sub -> mut Element {
element('sub').inline
}
fn pub mut sub -> mut Element
Adds a <sub>
element as a child element.
summary
Show source codeHide source code
fn pub mut summary -> mut Element {
element('summary').inline
}
fn pub mut summary -> mut Element
Adds a <summary>
element as a child element.
sup
Show source codeHide source code
fn pub mut sup -> mut Element {
element('sup').inline
}
fn pub mut sup -> mut Element
Adds a <sup>
element as a child element.
table
Show source codeHide source code
fn pub mut table -> mut Element {
element('table')
}
fn pub mut table -> mut Element
Adds a <table>
element as a child element.
tbody
Show source codeHide source code
fn pub mut tbody -> mut Element {
element('tbody')
}
fn pub mut tbody -> mut Element
Adds a <tbody>
element as a child element.
td
Show source codeHide source code
fn pub mut td -> mut Element {
element('td')
}
fn pub mut td -> mut Element
Adds a <td>
element as a child element.
template
Show source codeHide source code
fn pub mut template -> mut Element {
element('template')
}
fn pub mut template -> mut Element
Adds a <template>
element as a child element.
text
Show source codeHide source code
fn pub mut text(text: String) {
nodes_mut.push(Node.Text(text))
}
fn pub mut text(text: String)
Adds a text node to this element.
Examples
import builder.html.Element
Element.new('p').text('Hello!')
textarea
Show source codeHide source code
fn pub mut textarea -> mut Element {
element('textarea')
}
fn pub mut textarea -> mut Element
Adds a <textarea>
element as a child element.
tfoot
Show source codeHide source code
fn pub mut tfoot -> mut Element {
element('tfoot')
}
fn pub mut tfoot -> mut Element
Adds a <tfoot>
element as a child element.
th
Show source codeHide source code
fn pub mut th -> mut Element {
element('th')
}
fn pub mut th -> mut Element
Adds a <th>
element as a child element.
thead
Show source codeHide source code
fn pub mut thead -> mut Element {
element('thead')
}
fn pub mut thead -> mut Element
Adds a <thead>
element as a child element.
time
Show source codeHide source code
fn pub mut time -> mut Element {
element('time').inline
}
fn pub mut time -> mut Element
Adds a <time>
element as a child element.
title
Show source codeHide source code
fn pub mut title -> mut Element {
element('title')
}
fn pub mut title -> mut Element
Adds a <title>
element as a child element.
to_pretty_string
Show source codeHide source code
fn pub to_pretty_string -> String {
Generator.new(indent: ' ').generate(self)
}
fn pub to_pretty_string -> String
Returns an indented String
containing the HTML representation of self
.
This method uses two spaces for indentation. If you want to customize the
indentation, use the Generator
type directly instead.
Examples
import builder.html.Document
let doc = Document.new
doc.p.text('hello')
doc.to_pretty_string # => "<p>\n hello\n</p>"
to_string
Show source codeHide source code
fn pub to_string -> String {
Generator.new(indent: '').generate(self)
}
fn pub to_string -> String
Returns a String
containing the HTML representation of self
.
Examples
import builder.html.Document
let doc = Document.new
doc.p.text('hello')
doc.to_string # => '<p>hello</p>'
tr
Show source codeHide source code
fn pub mut tr -> mut Element {
element('tr')
}
fn pub mut tr -> mut Element
Adds a <tr>
element as a child element.
track
Show source codeHide source code
fn pub mut track -> mut Element {
element('track').self_closing
}
fn pub mut track -> mut Element
Adds a <track>
element as a child element.
u
Show source codeHide source code
fn pub mut u -> mut Element {
element('u')
}
fn pub mut u -> mut Element
Adds a <u>
element as a child element.
ul
Show source codeHide source code
fn pub mut ul -> mut Element {
element('ul')
}
fn pub mut ul -> mut Element
Adds a <ul>
element as a child element.
var
Show source codeHide source code
fn pub mut var -> mut Element {
element('var').inline
}
fn pub mut var -> mut Element
Adds a <var>
element as a child element.
video
Show source codeHide source code
fn pub mut video -> mut Element {
element('video')
}
fn pub mut video -> mut Element
Adds a <video>
element as a child element.
wbr
Show source codeHide source code
fn pub mut wbr -> mut Element {
element('wbr').self_closing
}
fn pub mut wbr -> mut Element
Adds a <wbr>
element as a child element.
xmp
Show source codeHide source code
fn pub mut xmp -> mut Element {
element('xmp')
}
fn pub mut xmp -> mut Element
Adds a <xmp>
element as a child element.
xperimental
Show source codeHide source code
fn pub mut xperimental -> mut Element {
element('xperimental')
}
fn pub mut xperimental -> mut Element
Adds a <xperimental>
element as a child element.
Implemented traits
Builder
impl Builder for Document
ToString
impl ToString for Document