html

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 2 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(c Component) string

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.

func (Attribute) Render

func (a Attribute) Render() string

Render the attribute, which qquotes the value verbatim. TODO: escaping

type BASE

type BASE struct{ HTMLElement }

func A

func A() *BASE

func Base

func Base() *BASE

type BODY

type BODY struct{ HTMLElement }

func Body

func Body() *BODY

type BUTTON

type BUTTON struct{ HTMLElement }

func Button

func Button() *BUTTON

type C

type C string

C is short for CDATA

func (C) Render

func (c C) Render(i int) string

type Component

type Component interface {
	Render() Element
}

Component is a metastructure that, when rendered, returns the root of an arbitrarily large element tree.

type DIV

type DIV struct{ HTMLElement }

func Div

func Div() *DIV

type DOCTYPE

type DOCTYPE string

func Doctype

func Doctype() DOCTYPE

func (DOCTYPE) Render

func (d DOCTYPE) Render(i int) string

type EM

type EM struct{ HTMLElement }

func Em

func Em() *EM

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.

func File

func File(path string) FILE

func (FILE) Render

func (f FILE) Render(i int) string

type FORM

type FORM struct{ HTMLElement }

func Form

func Form() *FORM
type HEAD struct{ HTMLElement }
func Head() *HEAD

type HTML

type HTML struct{ HTMLElement }

func Html

func Html() *HTML

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 Header1

type Header1 struct{ HTMLElement }

func H1

func H1() *Header1

type Header2

type Header2 struct{ HTMLElement }

func H2

func H2() *Header2

type Header3

type Header3 struct{ HTMLElement }

func H3

func H3() *Header3

type Header4

type Header4 struct{ HTMLElement }

func H4

func H4() *Header4

type Header5

type Header5 struct{ HTMLElement }

func H5

func H5() *Header5

type Header6

type Header6 struct{ HTMLElement }

func H6

func H6() *Header6

type I

type I struct{ HTMLElement }

func Italic

func Italic() *I

type IMG

type IMG struct{ HTMLElement }

func Img

func Img() *IMG

type INPUT

type INPUT struct{ HTMLElement }

func Input

func Input() *INPUT

type Item

type Item struct{ HTMLElement }

func LI

func LI() *Item

type LABEL

type LABEL struct{ HTMLElement }

func Label

func Label() *LABEL
type LINK struct{ HTMLElement }
func Link() *LINK

type META

type META struct{ HTMLElement }

func Meta

func Meta() *META

type Ordered

type Ordered struct{ HTMLElement }

func OL

func OL() *Ordered

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.

func Root

func Root() *ROOT

type Renderable

type Renderable interface {
	Render(i int) string
}

Renderable indicates that with a passed indentation level, the implementing instance will return a string suitable for rendering.

type SCRIPT

type SCRIPT struct{ HTMLElement }

func Script

func Script() *SCRIPT

type SPAN

type SPAN struct{ HTMLElement }

func Span

func Span() *SPAN

type TITLE

type TITLE struct{ HTMLElement }

func Title

func Title() *TITLE

type Unordered

type Unordered struct{ HTMLElement }

func UL

func UL() *Unordered

Jump to

Keyboard shortcuts

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