html

package module
v0.0.0-...-e869669 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2015 License: BSD-3-Clause Imports: 8 Imported by: 0

README

html

HTML generating tools.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// HTML Character Entity copyright
	COPY = HTMLNode("©")
	// HTML Character Entity ampersand
	AMP = HTMLNode("&")
	// HTML Character Entity less than
	LT = HTMLNode("<")
	// HTML Character Entity greater than
	GT = HTMLNode(">")
	// HTML Character Entity cent
	CENT = HTMLNode("¢")
	// HTML Character Entity pound
	POUND = HTMLNode("£")
	// HTML Character Entity yen
	YEN = HTMLNode("¥")
	// HTML Character Entity euro
	EURO = HTMLNode("€")
	// HTML Character Entity registered trademark
	REG = HTMLNode("®")
	// HTML Character Entity non-breaking space
	NBSP  = HTMLNode(" ")
	TIMES = HTMLNode("×")
	LAQUO = HTMLNode("«")
	RAQUO = HTMLNode("»")
)

HTML Entities

View Source
var DefaultOptions = RenderOptions{}

The default RenderOptions

Functions

This section is empty.

Types

type Attributes

type Attributes []attrInfo

func (*Attributes) Put

func (attrs *Attributes) Put(name, value HTMLNode)

func (Attributes) WriteTo

func (attrs Attributes) WriteTo(b Writer, sortAttr bool)

type Element

type Element struct {
	Void
	// contains filtered or unexported fields
}

Element is a Node with children.

func A

func A(href string, children ...Node) *Element

func B

func B(children ...Node) *Element

func BODY

func BODY() *Element

func BUTTON

func BUTTON(children ...Node) *Element

func CAPTION

func CAPTION(children ...Node) *Element

The caption element

func COLGROUP

func COLGROUP(span int, cols ...*Void) *Element

The colgroup element

If span > 0, cols are ignored. Otherwise, cols (col tags) are appended as children.

func DD

func DD(children ...Node) *Element

func DIV

func DIV(children ...Node) *Element

func DL

func DL(children ...Node) *Element

func DT

func DT(children ...Node) *Element
func FOOTER(children ...Node) *Element

func FORM

func FORM(method, action string, children ...Node) *Element

func H1

func H1(children ...Node) *Element

func H2

func H2(children ...Node) *Element

func H3

func H3(children ...Node) *Element

func H4

func H4(children ...Node) *Element

func H5

func H5(children ...Node) *Element

func H6

func H6(children ...Node) *Element
func HEAD() *Element

HEAD creates an HEAD element. http://www.w3.org/TR/html5/document-metadata.html#the-head-element

func LABEL

func LABEL(For string, children ...Node) *Element

func LI

func LI(children ...Node) *Element

func MAP

func MAP(name string, children ...Node) *Element

The map element.

Example
h := HTML("")
body := h.Body()
body.Child(MAP("menu", AREA("fun.html", "Fun", "circle", []int{1, 2, 3, 4})))
fmt.Println(NodeToHTMLNode(h, RenderOptions{SortAttr: true}))
Output:

<!DOCTYPE html>
<meta charset="utf-8"><map name="menu"><area alt="Fun" coords="12,3,4," href="fun.html" shape="circle"></map>
func NAV(children ...Node) *Element

func NOSCRIPT

func NOSCRIPT(children ...Node) *Element

func OBJECT

func OBJECT(children ...Node) *Element

func OL

func OL(children ...Node) *Element

func OPTGROUP

func OPTGROUP(label string, children ...*Element) *Element

func OPTION

func OPTION(value, text string) *Element

func P

func P(children ...Node) *Element

func PRE

func PRE(children ...Node) *Element

func RB

func RB(children ...Node) *Element

func RP

func RP(children ...Node) *Element

func RT

func RT(children ...Node) *Element

func RTC

func RTC(children ...Node) *Element

func RUBY

func RUBY(children ...Node) *Element

func SCRIPT

func SCRIPT(src URL, content string) *Element

func SELECT

func SELECT(children ...*Element) *Element

func SMALL

func SMALL(children ...Node) *Element

func SPAN

func SPAN(children ...Node) *Element

func TABLE

func TABLE(children ...*Element) *Element

The table element

Example
h := HTML("")
body := h.Body()
body.Child(TABLE(
	CAPTION(T("Hello")),
	COLGROUP(0,
		COL(2), COL(1),
	),
	COLGROUP(5),
	THEAD(
		TR(TH()),
	),
	TBODY(
		TR(TD()),
	),
	TFOOT(),
))
fmt.Println(NodeToHTMLNode(h, RenderOptions{SortAttr: true}))
Output:

<!DOCTYPE html>
<meta charset="utf-8"><table><caption>Hello</caption><col span="2"><col><colgroup span="5"><thead><tr><th><tbody><tr><td><tfoot></table>

func TBODY

func TBODY(trs ...*Element) *Element

The tbody element.

func TD

func TD(children ...Node) *Element

The td element.

func TEXTAREA

func TEXTAREA(name, value string, children ...Node) *Element

func TFOOT

func TFOOT(trs ...*Element) *Element

The tfoot element.

func TH

func TH(children ...Node) *Element

The th element.

func THEAD

func THEAD(trs ...*Element) *Element

The thead element.

func TITLE

func TITLE(title string) *Element

TITLE creats a TITLE element. http://www.w3.org/TR/html5/document-metadata.html#the-title-element TODO maybe this is not necessary, force user to use Html.Title since there

should not be more than one title

func TR

func TR(children ...*Element) *Element

func UL

func UL(children ...Node) *Element

func (*Element) AddClass

func (e *Element) AddClass(classes ...string) *Element

AddClass is same as Void.AddClass but returns a *Element.

func (*Element) Attr

func (e *Element) Attr(name string, value string) *Element

Attr is same as Void.Attr but returns a *Element.

func (*Element) Child

func (e *Element) Child(el ...Node) *Element

Child appends children of the Element.

func (*Element) ChildEls

func (e *Element) ChildEls(els ...*Element) *Element

ChildEls appends a list of *Element's as the children of the Element.

func (*Element) ChildVoids

func (e *Element) ChildVoids(vs ...*Void) *Element

ChildEls appends a list of *Void's as the children of the Element.

func (*Element) Children

func (t *Element) Children() []Element

Children returns the children of the element.

func (*Element) NonEmptyAttr

func (e *Element) NonEmptyAttr(name string, value string) *Element

NonEmptyAttr is same as Void.NonEmptyAttr but returns a *Element.

func (*Element) T

func (e *Element) T(txt string) *Element

T appends a text as a child of the Element.

func (*Element) WriteTo

func (e *Element) WriteTo(b Writer, opt RenderOptions, parent *Element, childIndex int)

type HTMLNode

type HTMLNode string

A string type representing an escaped HTML code

func NodeToHTMLNode

func NodeToHTMLNode(nd Node, opt RenderOptions) HTMLNode

NodeToHTMLBytes converts a Node into HTMLNode.

func NumEnt

func NumEnt(num int) HTMLNode

NumEnt returns HTMLBytes a numerical entity.

func T

func T(text string) HTMLNode

T returns an escaped HTMLNode of the specified text as contents

func Tf

func Tf(format string, args ...interface{}) HTMLNode

T returns an escaped HTMLNode of the specified formated text as contents

func (HTMLNode) Type

func (h HTMLNode) Type() TagType

func (HTMLNode) WriteRaw

func (h HTMLNode) WriteRaw(b Writer)

func (HTMLNode) WriteTo

func (h HTMLNode) WriteTo(b Writer, opt RenderOptions, parent *Element, childIndex int)

type Html

type Html struct {
	Element
}

Html represents an HTML element. Do not create Html directly, call HTML function instead.

func HTML

func HTML(lang string) *Html

HTML creates an HTML element with type Html. http://www.w3.org/TR/html5/semantics.html#the-html-element

func (*Html) Base

func (h *Html) Base(href URL, target string) *Html

func (*Html) Body

func (h *Html) Body() *Element

func (*Html) Child

func (e *Html) Child()

Child just panics. Should call Head and Body methods instead.

func (*Html) Css

func (h *Html) Css(href URL) *Html

func (*Html) Favicon

func (h *Html) Favicon(href URL, tp string) *Html

func (*Html) Head

func (h *Html) Head() *Element

func (*Html) Lang

func (h *Html) Lang(lang string) *Html

func (*Html) Manifest

func (h *Html) Manifest(src URL) *Html

Manifest sets the "manifest" attribute of the HTML node.

func (*Html) SCRIPT

func (h *Html) SCRIPT(src URL, content string) *Html

func (*Html) Title

func (h *Html) Title(title string) *Html

func (*Html) Type

func (h *Html) Type() TagType

Implementation of Node interface

func (*Html) WriteTo

func (h *Html) WriteTo(b Writer, opt RenderOptions, parent *Element, childIndex int)

Implementation of Node interface

type Node

type Node interface {
	Type() TagType
	WriteTo(w Writer, opt RenderOptions, parent *Element, childIndex int)
}

type RenderOptions

type RenderOptions struct {
	Ident HTMLNode
	// Don't apply HTML5 omitting.
	DisableOmit bool
	// Sort attributes names before export.
	// This is useful for testing because otherwise the exported attributes could be unpredictable.
	SortAttr bool
}

type Void

type Void struct {
	// contains filtered or unexported fields
}

An HTML void element

func AREA

func AREA(href, alt string, shape string, coords []int) *Void

The area element

func BASE

func BASE(href URL, target string) *Void

BASE creates a base element. http://www.w3.org/TR/html5/document-metadata.html#the-base-element TODO maybe this is not necessary, force user to use Html.Base since there

should not be more than one base
Example
h := HTML("")
head := h.Head()
head.Child(BASE("/images", "_blank"))
fmt.Println(NodeToHTMLNode(h, RenderOptions{SortAttr: true}))
Output:

<!DOCTYPE html>
<meta charset="utf-8"><base href="/images" target="_blank">

func BR

func BR() *Void

The br element

func COL

func COL(span int) *Void

The col element. span is the number of columns spanned by the element.

func EMBED

func EMBED(src URL, tp string, width, height int) *Void

The embed element.

tp is the type attribute. Empty string will be ignored. width or height with a negative value will be ignored.

Example
h := HTML("")
h.Body().Child(
	EMBED(URL("http://example.com/a.swf"), "flash", 100, 200),
	EMBED(URL("http://example.com/a.swf"), "", -1, -1),
)
fmt.Println(NodeToHTMLNode(h, RenderOptions{SortAttr: true}))
Output:

<!DOCTYPE html>
<meta charset="utf-8"><embed height="200" src="http://example.com/a.swf" type="flash" width="100"><embed src="http://example.com/a.swf">

func HR

func HR() *Void

The br element

Example
h := HTML("")
h.Body().Child(HR())
fmt.Println(NodeToHTMLNode(h, RenderOptions{SortAttr: true}))
Output:

<!DOCTYPE html>
<meta charset="utf-8"><hr>

func IMG

func IMG(src URL, alt string) *Void

func INPUT

func INPUT(tp, name, value string) *Void
func LINK(href URL, rel string) *Void

LINK creates a link element. http://www.w3.org/TR/html5/document-metadata.html#the-link-element

func META

func META() *Void

func PARAM

func PARAM(name, value string) *Void

func (*Void) AddClass

func (v *Void) AddClass(classes ...string) *Void

AddClass adds a class into the class list of the node.

func (*Void) Attr

func (v *Void) Attr(name string, value string) *Void

func (*Void) AttrIfNotEmpty

func (v *Void) AttrIfNotEmpty(name, value string) *Void

func (*Void) DelClass

func (v *Void) DelClass(classes ...string) *Void

DelClass deletes a class from the class list of the node.

func (*Void) ID

func (t *Void) ID(id string) *Void

ID sets the "id" attribute of the node.

func (*Void) Name

func (v *Void) Name() HTMLNode

func (*Void) NonEmptyAttr

func (v *Void) NonEmptyAttr(name, value string) *Void

NonEmptyAttr sets the attribute is value is not empty.

func (*Void) TabIndex

func (v *Void) TabIndex(tablInex int)

TabIndex sets the "tabindex" attribute of the node

func (*Void) Title

func (v *Void) Title(title string)

Title sets the title attribute of the node.

func (*Void) Type

func (v *Void) Type() TagType

func (*Void) WriteTo

func (v *Void) WriteTo(b Writer, opt RenderOptions, parent *Element, childIndex int)

Implementation of Node.WriteTo. This will be called to generate open tags of both void and normal elements

type Writer

type Writer interface {
	io.ByteWriter
	io.Writer
	WriteString(string) (int, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL