Documentation
¶
Overview ¶
Package html provides functions and types for efficiently building HTML documents.
Index ¶
- type Builder
- func (b *Builder) A(href string) *Element
- func (b *Builder) Audio() *Element
- func (b *Builder) B(class string) *Element
- func (b *Builder) BR() *Element
- func (b *Builder) Body() *Element
- func (b *Builder) Button() *Element
- func (builder *Builder) Bytes() []byte
- func (builder *Builder) Close() *Builder
- func (builder *Builder) CloseAll() *Builder
- func (builder *Builder) Container(name string) *Element
- func (b *Builder) Datalist(id string) *Element
- func (b *Builder) Div() *Element
- func (builder *Builder) Element(name string, container bool) *Element
- func (builder *Builder) Empty(name string) *Element
- func (builder *Builder) EndBracket() *Builder
- func (b *Builder) FigCaption(innerHTML string) *Element
- func (b *Builder) Figure() *Element
- func (b *Builder) Form(method string, action string) *Element
- func (b *Builder) H1() *Element
- func (b *Builder) H2() *Element
- func (b *Builder) H3() *Element
- func (b *Builder) HTML() *Element
- func (b *Builder) Head() *Element
- func (b *Builder) I(classes ...string) *Element
- func (b *Builder) Img(src string) *Element
- func (b *Builder) Input(t string, name string) *Element
- func (b *Builder) Label(forID string) *Element
- func (b *Builder) Link(rel string, href string) *Element
- func (b *Builder) OptGroup(label string) *Element
- func (b *Builder) Option(label string, value string) *Element
- func (b *Builder) OptionSelected(label string, value string) *Element
- func (b *Builder) Picture() *Element
- func (builder *Builder) ReadString() string
- func (builder *Builder) Reader() io.Reader
- func (b *Builder) Script() *Element
- func (b *Builder) Select(name string) *Element
- func (b *Builder) Source() *Element
- func (builder *Builder) Space() *Builder
- func (b *Builder) Span() *Element
- func (builder *Builder) String() string
- func (b *Builder) Stylesheet(url string) *Element
- func (builder *Builder) SubTree() *Builder
- func (b *Builder) TBody() *Element
- func (b *Builder) TD() *Element
- func (b *Builder) TH() *Element
- func (b *Builder) TR() *Element
- func (b *Builder) Table() *Element
- func (b *Builder) Textarea(name string) *Element
- func (b *Builder) Title(value string) *Element
- type Element
- func (element *Element) Aria(name string, value string) *Element
- func (element *Element) Attr(name string, value string) *Element
- func (element *Element) Class(values ...string) *Element
- func (element *Element) Close() *Element
- func (element *Element) Data(name string, value string) *Element
- func (element *Element) EndBracket() *Element
- func (element *Element) For(value string) *Element
- func (element *Element) ForceAttr(name string, value string) *Element
- func (element *Element) Href(url string) *Element
- func (element *Element) HxGet(value string) *Element
- func (element *Element) HxPost(value string) *Element
- func (element *Element) HxSwap(value string) *Element
- func (element *Element) HxTarget(value string) *Element
- func (element *Element) HxTrigger(value string) *Element
- func (element *Element) ID(value string) *Element
- func (element *Element) InnerHTML(innerHTML string) *Element
- func (element *Element) InnerText(text string) *Element
- func (element *Element) Label(value string) *Element
- func (element *Element) List(value string) *Element
- func (element *Element) Media(value string) *Element
- func (element *Element) Name(value string) *Element
- func (element *Element) Rel(value string) *Element
- func (element *Element) Role(value string) *Element
- func (element *Element) Script(value ...string) *Element
- func (element *Element) Src(value string) *Element
- func (element *Element) SrcSet(value string) *Element
- func (element *Element) Start() *Element
- func (element *Element) Style(values ...string) *Element
- func (element *Element) TabIndex(value string) *Element
- func (element *Element) Type(value string) *Element
- func (element *Element) Value(value string) *Element
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶ added in v0.9.0
Builder collects tags and attributes into a strings.Builder efficiently.
func (*Builder) A ¶ added in v0.10.1
A creates a new anchor element with the specified href https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
func (*Builder) Audio ¶ added in v0.16.5
Audio creates a new abbreviation element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
func (*Builder) B ¶ added in v0.11.2
B creates a new bold element with the specified class https://developer.mozilla.org/en-US/docs/Web/HTML/Element/b
func (*Builder) BR ¶ added in v0.9.0
BR creates a new line break element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br
func (*Builder) Body ¶ added in v0.16.4
Body creates a new body element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body
func (*Builder) Button ¶ added in v0.10.0
Button creates a new button element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button
func (*Builder) Close ¶ added in v0.9.0
Close completes the last tag on the stack, then pops it off of the stack
func (*Builder) Container ¶ added in v0.9.0
Container creates a new "container" element that WILL have an end tag.
func (*Builder) Datalist ¶ added in v0.10.0
Datalist creates a new datalist element with the specified ID https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist
func (*Builder) Div ¶ added in v0.9.0
Div creates a new div element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div
func (*Builder) Empty ¶ added in v0.9.0
Empty creates a new "empty" or non-container element that WILL NOT have an end tag
func (*Builder) EndBracket ¶ added in v0.11.2
EndBracket adds an end bracket to the last tag on the stack
func (*Builder) FigCaption ¶ added in v0.16.7
FigCaption creates a new figcaption element with the specified inner HTML https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption
func (*Builder) Figure ¶ added in v0.16.7
Figure creates a new figure element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure
func (*Builder) Form ¶ added in v0.11.0
Form creates a new form element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
func (*Builder) H1 ¶ added in v0.11.2
H1 creates a new h1 element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h1
func (*Builder) H2 ¶ added in v0.11.2
H2 creates a new h2 element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h2
func (*Builder) H3 ¶ added in v0.11.2
H3 creates a new h3 element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h3
func (*Builder) HTML ¶ added in v0.16.4
HTML creates a new html element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html
func (*Builder) Head ¶ added in v0.16.4
Head creates a new head element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head
func (*Builder) I ¶ added in v0.11.2
I creates a new italics element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/i
func (*Builder) Img ¶ added in v0.16.5
Img creates a new image element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
func (*Builder) Input ¶ added in v0.9.0
Input creates a new input element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
func (*Builder) Label ¶ added in v0.9.0
Label creates a new label element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label
func (*Builder) Link ¶ added in v0.11.5
Link creates a new link element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
func (*Builder) OptGroup ¶ added in v0.10.0
OptGroup creates a new meta element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup
func (*Builder) Option ¶ added in v0.10.0
Option creates a new option element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option
func (*Builder) OptionSelected ¶ added in v0.16.6
OptionSelected creates a new option element with the "selected" attribute set to true https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option
func (*Builder) Picture ¶ added in v0.16.7
Picture creates a new picture element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture
func (*Builder) ReadString ¶ added in v0.12.1
ReadString reads the existing contents of the buffer but DOES NOT close any existing tags. This is useful for reading the header of an HTML document before calling a subroutine that will fill in its body.
func (*Builder) Script ¶ added in v0.11.0
Script creates a new script element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
func (*Builder) Select ¶ added in v0.10.0
Select creates a new select element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select
func (*Builder) Source ¶ added in v0.16.5
Source creates a new source element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/source
func (*Builder) Span ¶ added in v0.9.0
Span creates a new span element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
func (*Builder) String ¶ added in v0.9.0
String returns the assembled HTML as a string. It overrides the default behavior of the strings.Builder by also calling CloseAll() on all unclosed tags in the stack before generating HTML.
func (*Builder) Stylesheet ¶ added in v0.12.1
Stylesheet creates a new link element for a stylesheet https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
func (*Builder) SubTree ¶ added in v0.9.0
SubTree generates a new Builder that shares this Builder's string buffer. This is useful when sending a Builder to another function, so that the other function can maintain it's own stack of elements -- and potentially call .CloseAll() -- without affecting this current builder.
func (*Builder) TBody ¶ added in v0.14.1
TBody creates a new table body element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody
func (*Builder) TD ¶ added in v0.11.2
TD creates a new table data element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td
func (*Builder) TH ¶ added in v0.11.2
TH creates a new table header element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th
func (*Builder) TR ¶ added in v0.11.2
TR creates a new table row element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr
func (*Builder) Table ¶ added in v0.11.2
Table creates a new table element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table
func (*Builder) Textarea ¶ added in v0.10.0
Textarea creates a new textarea element https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
type Element ¶ added in v0.9.0
type Element struct {
// contains filtered or unexported fields
}
Element represents a element that is being written into the provided strings.Builder
func (*Element) Attr ¶ added in v0.9.0
Attr writes the attribute into the string builder. It converts the value (second parameter) into a string, and then uses html.EscapeString to escape the attribute value. Attribute names ARE NOT escaped. Empty values are not written to the builder.
func (*Element) Class ¶ added in v0.9.0
Class adds a "class" attribute to the Element. Multiple class names can be passed, and are separated by spaces
func (*Element) Close ¶ added in v0.9.0
Close writes the necessary closing tag for this element and marks it closed
func (*Element) EndBracket ¶ added in v0.9.0
EndBracket writes the final ">" of the beginning element to the strings.Builder It uses an internal variable to prevent duplicate calls
func (*Element) ForceAttr ¶ added in v0.16.6
ForceAttr writes the attribute into the string builder. It converts the value (second parameter) into a string, and then uses html.EscapeString to escape the attribute value. Attribute names ARE NOT escaped. Empty values ARE written to the builder
func (*Element) HxTrigger ¶ added in v0.16.16
HxTrigger adds a "hx-trigger" attribute to the Element
func (*Element) InnerHTML ¶ added in v0.9.0
InnerHTML does three things: 1) closes the beginning element (if needed) 2) appends innerHTML (if provided) 3) writes an ending element to the builder (ie. </element> ) InnerHTML DOES NOT escape its content, so it is not safe to use with user-generated content.
func (*Element) InnerText ¶ added in v0.16.0
InnerText works similarly to the InnerHTML method. In addition, it HTML escapes its content so that user-generated-content can be inserted into the output safely.
func (*Element) Rel ¶ added in v0.12.1
Rel adds a "rel" (relationship) attribute to the Element (valid values listed at https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel)
func (*Element) Script ¶ added in v0.10.0
Script adds a "data-script" attribute to the Element (for https://hyperscript.org)
func (*Element) Start ¶ added in v0.9.0
Start writes the initial tag name and opening bracket for this tag.
func (*Element) Style ¶ added in v0.11.2
Style adds a "style" attribute to the Element Multiple style definitions can be passed, and are separated by semicolons.