Documentation
¶
Overview ¶
package html defines renderable HTML primitives. It's raw. It's verbose. It's oft opinionated in what it omits. But it endeavors to be strictly correct with what it does. For something more friendly, see the ui package.
Index ¶
- func Render(c Component) string
- type Anchor
- type Attribute
- type BASE
- type BODY
- type BUTTON
- type C
- type Component
- type DIV
- type DOCTYPE
- type EM
- type Element
- type FILE
- type FORM
- type HEAD
- type HTML
- type HTMLElement
- func (t *HTMLElement) Add(r ...Renderable) Element
- func (t *HTMLElement) AddText(text string) Element
- func (t *HTMLElement) Attributes() []Attribute
- func (t *HTMLElement) Children() []Renderable
- func (t *HTMLElement) Empty() bool
- func (t *HTMLElement) Inline() bool
- func (t *HTMLElement) Key() string
- func (t *HTMLElement) Render(i int) string
- func (t *HTMLElement) Set(k, v string) Element
- type Header1
- type Header2
- type Header3
- type Header4
- type Header5
- type Header6
- type I
- type IMG
- type INPUT
- type Item
- type LABEL
- type LINK
- type META
- type Ordered
- type ROOT
- type Renderable
- type SCRIPT
- type SPAN
- type TITLE
- type Unordered
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Anchor ¶
type Anchor struct{ HTMLElement }
type Attribute ¶
type Attribute struct {
Key, Value string
}
Attribute is a tag attribute consiting of a key and a value.
type Component ¶
type Component interface {
Render() Element
}
Component is a metastructure that, when rendered, returns the root of an arbitrarily large element tree.
type Element ¶
type Element interface { Renderable Key() string Empty() bool Inline() bool Set(string, string) Element Attributes() []Attribute Add(...Renderable) Element Children() []Renderable }
Element is a renderable with other
type FILE ¶
type FILE struct {
Path string
}
FILE is a renderable structure that is a file substitution for raw (unsafe and non-autoformatted) plain text.
type HTMLElement ¶
type HTMLElement struct {
// contains filtered or unexported fields
}
Element is a representation of an HTML element. An element consists of either an empty tag <img /> or standard tag <div></div>, with attributes <div key="value"> and potentially children if it is not empty <div><img /></div> When rendered, a tag will be indented based on its level of nesting, and will have linebreaks in the appropriate place depending on it's being either an inline or non-inline element.
func (*HTMLElement) Add ¶
func (t *HTMLElement) Add(r ...Renderable) Element
Add something renderable to the element's children
func (*HTMLElement) AddText ¶
func (t *HTMLElement) AddText(text string) Element
AddText is a convenience method for Add(C(text))
func (*HTMLElement) Attributes ¶
func (t *HTMLElement) Attributes() []Attribute
func (*HTMLElement) Children ¶
func (t *HTMLElement) Children() []Renderable
func (*HTMLElement) Empty ¶
func (t *HTMLElement) Empty() bool
func (*HTMLElement) Inline ¶
func (t *HTMLElement) Inline() bool
func (*HTMLElement) Key ¶
func (t *HTMLElement) Key() string
func (*HTMLElement) Render ¶
func (t *HTMLElement) Render(i int) string
Render the element including recursively rendering its children.
func (*HTMLElement) Set ¶
func (t *HTMLElement) Set(k, v string) Element
Set the value of an attribute on the start tag of the element. <tagname key="value"></tagname>
type ROOT ¶
type ROOT struct{ HTMLElement }
ROOT is a special case denoting the ephemeral single parent of the two root elements DOCTYPE and HTML. It is created as the ROOT of a page, and the DOCTYPE and HTML elements added. The empty key results in no tags or attributes being written; only the children elements.
type Renderable ¶
Renderable indicates that with a passed indentation level, the implementing instance will return a string suitable for rendering.