gohtml

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: BSD-1-Clause Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const DOCTYPE string = "<!DOCTYPE html>\r\n"

Default document type declaration

Variables

View Source
var ErrOverflow = errors.New("elementBuffer: buffer overflow")

Overflows are not recoverable, and will cause a panic.

Functions

func ForEach

func ForEach[T ElementConstraint](s T, f func(int, T))

func NewBuffer

func NewBuffer(bufLen int, panicOnError ...bool) *elementBuffer

NewBuffer creates a new elementBuffer with the given size.

If panicOnError is true, any overflow will cause a panic.

Types

type Attr

type Attr[T any] struct {
	Key       string // The key of the attribute.
	Value     T      // The value of the attribute.
	Delimiter string // The delimiter to use when rendering the value.
	// contains filtered or unexported fields
}

Attr represents an attribute of an element.

func NewAttr

func NewAttr[T any](k string, v T) Attr[T]

func NewBoolAttr

func NewBoolAttr(k string, v bool) Attr[bool]

NewBoolAttr creates a new boolean attribute.

func NewStringAttr

func NewStringAttr(k string, v []string, d string) Attr[[]string]

NewStringAttr creates a new string attribute.

func (Attr[T]) String

func (a Attr[T]) String() string

func (Attr[T]) ToBuffer

func (a Attr[T]) ToBuffer(b *elementBuffer)

type Document

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

Document represents an HTML document

It is a wrapper around a predefined HTML() element.

func NewDocument

func NewDocument() *Document

NewDocument creates a new HTML document

func (*Document) Body

func (d *Document) Body() *Element

Get the document's body element. If it does not exist, create it.

func (*Document) Buffer

func (d *Document) Buffer() *elementBuffer

Buffer returns the document as an elementBuffer

func (*Document) Bytes

func (d *Document) Bytes() []byte

Bytes returns the document as a byte slice

func (*Document) GetElementByID

func (d *Document) GetElementByID(id string) *Element

Get an element by its ID.

func (*Document) GetElementsByClassName

func (d *Document) GetElementsByClassName(className string) []*Element

Get elements by their class name.

func (*Document) GetElementsByTagName

func (d *Document) GetElementsByTagName(tagName string) []*Element

Get elements by their tag name.

func (*Document) Head

func (d *Document) Head() *Element

Get the document's head element. If it does not exist, create it.

func (*Document) Len

func (d *Document) Len() int

Len returns the length of the document

func (*Document) Render

func (d *Document) Render(w io.Writer) error

Render writes the document to the given io.Writer

func (*Document) Root

func (d *Document) Root() *Element

Get the document's root element.

func (*Document) String

func (d *Document) String() string

String returns the document as a string

type Element

type Element struct {
	Type      string     // The type of element, e.g. "div", "span", "input", etc.
	InnerText string     // The inner text of the element, if any.
	AutoClose bool       // Whether or not the element is self closing.
	Children  []*Element // List of child elements.

	BoolAttrs    []Attr[bool]     // List of boolean attributes.
	SemicolAttrs []Attr[[]string] // List of attributes that are separated by semicolons.
	Attrs        []Attr[[]string] // List of attributes that are separated by spaces.
	// contains filtered or unexported fields
}

Element is a single HTML element.

func Add

func Add[T1, T2 ElementConstraint](elem T1, children ...T2) *Element

Add adds a child to the element.

func HTML

func HTML() *Element

func NewElement

func NewElement(t string) *Element

NewElement creates a new element.

func UnRestrain

func UnRestrain[T ElementConstraint](e T) *Element

func (*Element) A

func (e *Element) A(href string) *Element

func (*Element) Abbr

func (e *Element) Abbr() *Element

func (*Element) Add

func (e *Element) Add(children ...*Element) *Element

AddChild adds a child to the element.

func (*Element) Address

func (e *Element) Address() *Element

func (*Element) Area

func (e *Element) Area() *Element

func (*Element) Article

func (e *Element) Article() *Element

func (*Element) Aside

func (e *Element) Aside() *Element

func (*Element) AsyncForEach

func (e *Element) AsyncForEach(fn func(*Element) bool)

Loop over all inner elements recursively asynchronously.

func (*Element) Attr

func (e *Element) Attr(k string, v ...string) *Element

Attr adds an attribute to the element.

func (*Element) AttrBool

func (e *Element) AttrBool(k string, v bool) *Element

AttrBool adds a boolean attribute to the element.

func (*Element) AttrSemiCol

func (e *Element) AttrSemiCol(k string, v ...string) *Element

AttrSemiCol adds an attribute to the element.

func (*Element) Audio

func (e *Element) Audio() *Element

func (*Element) B

func (e *Element) B() *Element

func (*Element) Bdi

func (e *Element) Bdi() *Element

func (*Element) Bdo

func (e *Element) Bdo() *Element

func (*Element) Blockquote

func (e *Element) Blockquote() *Element

func (*Element) Body

func (e *Element) Body() *Element

func (*Element) Br

func (e *Element) Br() *Element

func (*Element) Button

func (e *Element) Button() *Element

func (*Element) Canvas

func (e *Element) Canvas() *Element

func (*Element) Caption

func (e *Element) Caption() *Element

func (*Element) Cite

func (e *Element) Cite() *Element

func (*Element) Class

func (e *Element) Class(class ...string) *Element

Class sets the class attribute of the element. If the element already has a class attribute, it will be overwritten. If the class is an empty string, the class attribute will be removed.

func (*Element) Code

func (e *Element) Code() *Element

func (*Element) Col

func (e *Element) Col() *Element

func (*Element) Colgroup

func (e *Element) Colgroup() *Element

func (*Element) Command

func (e *Element) Command() *Element

func (*Element) Datalist

func (e *Element) Datalist() *Element

func (*Element) Dd

func (e *Element) Dd() *Element

func (*Element) Del

func (e *Element) Del() *Element

func (*Element) DelAttr

func (e *Element) DelAttr(k string) *Element

DelAttr removes an attribute from the element.

func (*Element) Details

func (e *Element) Details() *Element

func (*Element) Dfn

func (e *Element) Dfn() *Element

func (*Element) Div

func (e *Element) Div() *Element

func (*Element) Dl

func (e *Element) Dl() *Element

func (*Element) Dt

func (e *Element) Dt() *Element

func (*Element) Element

func (e *Element) Element(elementType string) *Element

func (*Element) Em

func (e *Element) Em() *Element

func (*Element) Embed

func (e *Element) Embed() *Element

func (*Element) Fieldset

func (e *Element) Fieldset() *Element

func (*Element) Figcaption

func (e *Element) Figcaption() *Element

func (*Element) Figure

func (e *Element) Figure() *Element

func (*Element) Footer

func (e *Element) Footer() *Element

func (*Element) For

func (e *Element) For(start, iterations, step int, f func(int) *Element) *Element

func (*Element) ForEach

func (e *Element) ForEach(f func(int, *Element)) *Element

Loop over all inner elements recursively.

func (*Element) Form

func (e *Element) Form() *Element

func (*Element) GetAttr

func (e *Element) GetAttr(k string) (stringsAttr []string, boolAttr, found bool)

GetAttr returns the attribute value.

func (*Element) GetElementByElement

func (e *Element) GetElementByElement(elem *Element) *Element

Get an element by another element!

func (*Element) GetElementByID

func (e *Element) GetElementByID(id string) *Element

Get inner elements by ID

func (*Element) GetElementsByClassName

func (e *Element) GetElementsByClassName(className string) []*Element

Get inner elements by classname

func (*Element) GetElementsByTagName

func (e *Element) GetElementsByTagName(tagName string) []*Element

Get inner elements by tag name

func (*Element) H1

func (e *Element) H1() *Element

func (*Element) H2

func (e *Element) H2() *Element

func (*Element) H3

func (e *Element) H3() *Element

func (*Element) H4

func (e *Element) H4() *Element

func (*Element) H5

func (e *Element) H5() *Element

func (*Element) H6

func (e *Element) H6() *Element

func (*Element) HTML

func (e *Element) HTML(s string) *Element

Writes raw HTML to the element.

Returns the element on which this method is called.

func (*Element) Header

func (e *Element) Header() *Element

func (*Element) Hr

func (e *Element) Hr() *RestrainedElement

func (*Element) I

func (e *Element) I() *Element

func (*Element) ID

func (e *Element) ID(id string) *Element

ID sets the id attribute of the element. If the element already has an id attribute, it will be overwritten. If the id is an empty string, the id attribute will be removed.

func (*Element) Iframe

func (e *Element) Iframe() *Element

func (*Element) Img

func (e *Element) Img(src string, alt ...string) *Element

func (*Element) Input

func (e *Element) Input() *RestrainedElement

TYPE -> (NAME, ID) -> PLACEHOLDER -> VALUE

func (*Element) Ins

func (e *Element) Ins() *Element

func (*Element) Kbd

func (e *Element) Kbd() *Element

func (*Element) Keygen

func (e *Element) Keygen() *Element

func (*Element) Label

func (e *Element) Label() *Element

func (*Element) Legend

func (e *Element) Legend() *Element

func (*Element) Main

func (e *Element) Main() *Element

func (*Element) Map

func (e *Element) Map() *Element

func (*Element) Mark

func (e *Element) Mark() *Element

func (*Element) Menu

func (e *Element) Menu() *Element

func (*Element) MetaCharset

func (e *Element) MetaCharset(v string) *RestrainedElement

func (*Element) MetaTag

func (e *Element) MetaTag(name string, content string) *RestrainedElement

func (*Element) Meter

func (e *Element) Meter() *Element

func (*Element) Nav

func (e *Element) Nav() *Element

func (*Element) NextChild

func (e *Element) NextChild() *Element

NextChild returns the next child element of the current elements parent. If the current element is the last child, nil is returned.

func (*Element) NoClose

func (e *Element) NoClose() *Element

NoClose sets the element to not close.

func (*Element) Object

func (e *Element) Object() *Element

func (*Element) Ol

func (e *Element) Ol() *HTMLLIST

func (*Element) Optgroup

func (e *Element) Optgroup() *Element

func (*Element) Output

func (e *Element) Output() *Element

func (*Element) P

func (e *Element) P() *Element

func (*Element) Param

func (e *Element) Param() *Element

func (*Element) Pre

func (e *Element) Pre() *Element

func (*Element) PrevChild

func (e *Element) PrevChild() *Element

PrevChild returns the previous child element of the current elements parent. If the current element is the first child, nil is returned.

func (*Element) Progress

func (e *Element) Progress() *Element

func (*Element) Q

func (e *Element) Q() *Element

func (*Element) Rp

func (e *Element) Rp() *Element

func (*Element) Rt

func (e *Element) Rt() *Element

func (*Element) Ruby

func (e *Element) Ruby() *Element

func (*Element) S

func (e *Element) S() *Element

func (*Element) Samp

func (e *Element) Samp() *Element

func (*Element) Section

func (e *Element) Section() *Element

func (*Element) Select

func (e *Element) Select(name string) *HTMLSELECT

Takes the text to be displayed and a list of items to be selected from

func (*Element) Small

func (e *Element) Small() *Element

func (*Element) Source

func (e *Element) Source() *Element

func (*Element) Span

func (e *Element) Span() *Element

func (*Element) String

func (e *Element) String() string

String returns the HTML string.

func (*Element) Strong

func (e *Element) Strong() *Element

func (*Element) Sub

func (e *Element) Sub() *Element

func (*Element) Summary

func (e *Element) Summary() *Element

func (*Element) Sup

func (e *Element) Sup() *Element

func (*Element) Table

func (e *Element) Table() *HTMLTABLE

func (*Element) Text

func (e *Element) Text(s string) *Element

Write text to the element.

Returns the element on which this method is called.

func (*Element) Textarea

func (e *Element) Textarea() *Element

func (*Element) Textf

func (e *Element) Textf(format string, a ...interface{}) *Element

Write text to the element using a format string.

Returns the element on which this method is called.

func (*Element) Time

func (e *Element) Time() *Element

func (*Element) Track

func (e *Element) Track() *Element

func (*Element) U

func (e *Element) U() *Element

func (*Element) Ul

func (e *Element) Ul() *HTMLLIST

func (*Element) Var

func (e *Element) Var() *Element

func (*Element) Video

func (e *Element) Video() *Element

func (*Element) Wbr

func (e *Element) Wbr() *Element

type ElementConstraint

type ElementConstraint interface {
	*Element | *HTMLLIST | *HTMLSELECT | *HTMLTABLE | *RestrainedElement
}

type HTMLLIST

type HTMLLIST Element

func (*HTMLLIST) Li

func (e *HTMLLIST) Li() *Element

type HTMLSELECT

type HTMLSELECT Element

func (*HTMLSELECT) Option

func (e *HTMLSELECT) Option(value, text string) *Element

type HTMLTABLE

type HTMLTABLE Element

func (*HTMLTABLE) Tbody

func (e *HTMLTABLE) Tbody() *Element

func (*HTMLTABLE) Td

func (e *HTMLTABLE) Td() *Element

func (*HTMLTABLE) Tfoot

func (e *HTMLTABLE) Tfoot() *Element

func (*HTMLTABLE) Th

func (e *HTMLTABLE) Th() *Element

func (*HTMLTABLE) Thead

func (e *HTMLTABLE) Thead() *Element

func (*HTMLTABLE) Tr

func (e *HTMLTABLE) Tr() *Element

type RestrainedElement

type RestrainedElement Element

func Restrain

func Restrain[T ElementConstraint](e T) *RestrainedElement

func (*RestrainedElement) Attr

This method is used to set an attribute on an element. It returns the element for inlining purposes.

func (*RestrainedElement) AttrBool

func (e *RestrainedElement) AttrBool(k string, v bool) *RestrainedElement

This method is used to set a boolean attribute on an element. It returns the element for inlining purposes.

func (*RestrainedElement) AttrSemicol

func (e *RestrainedElement) AttrSemicol(k string, v ...string) *RestrainedElement

This method is used to set an attribute on an element. It returns the element for inlining purposes.

Jump to

Keyboard shortcuts

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