Documentation ¶
Overview ¶
Package html_simple provides a safe and ergonomic HTML generation library with built-in XSS protection and compile-time HTML structure validation.
Index ¶
- type Attribute
- type Attributes
- type Element
- func (e *Element) A() *Element
- func (e *Element) Abbr() *Element
- func (e *Element) Acronym() *Element
- func (e *Element) Add(tag NormalTag) *Element
- func (e *Element) AddString(content string) *Element
- func (e *Element) AddVoid(tag VoidTag) *Element
- func (e *Element) Address() *Element
- func (e *Element) Area() *Element
- func (e *Element) Article() *Element
- func (e *Element) Aside() *Element
- func (e *Element) Attr(key, value string) *Element
- func (e *Element) Audio() *Element
- func (e *Element) B() *Element
- func (e *Element) Base() *Element
- func (e *Element) Bdi() *Element
- func (e *Element) Bdo() *Element
- func (e *Element) Big() *Element
- func (e *Element) Blockquote() *Element
- func (e *Element) Body() *Element
- func (e *Element) Br() *Element
- func (e *Element) Button() *Element
- func (e *Element) Canvas() *Element
- func (e *Element) Caption() *Element
- func (e *Element) Center() *Element
- func (e *Element) Cite() *Element
- func (e *Element) Code() *Element
- func (e *Element) Col() *Element
- func (e *Element) Colgroup() *Element
- func (e *Element) Data() *Element
- func (e *Element) Datalist() *Element
- func (e *Element) Dd() *Element
- func (e *Element) Del() *Element
- func (e *Element) Details() *Element
- func (e *Element) Dfn() *Element
- func (e *Element) Dialog() *Element
- func (e *Element) Dir() *Element
- func (e *Element) Div() *Element
- func (e *Element) Dl() *Element
- func (e *Element) Dt() *Element
- func (e *Element) Em() *Element
- func (e *Element) Embed() *Element
- func (e *Element) Fencedframe() *Element
- func (e *Element) Fieldset() *Element
- func (e *Element) Figcaption() *Element
- func (e *Element) Figure() *Element
- func (e *Element) Font() *Element
- func (e *Element) Footer() *Element
- func (e *Element) Form() *Element
- func (e *Element) Frame() *Element
- func (e *Element) Frameset() *Element
- func (e *Element) H1() *Element
- func (e *Element) Head() *Element
- func (e *Element) Header() *Element
- func (e *Element) Hgroup() *Element
- func (e *Element) Hr() *Element
- func (e *Element) Html() *Element
- func (e *Element) I() *Element
- func (e *Element) Iframe() *Element
- func (e *Element) Img() *Element
- func (e *Element) Input() *Element
- func (e *Element) Ins() *Element
- func (e *Element) Kbd() *Element
- func (e *Element) Label() *Element
- func (e *Element) Legend() *Element
- func (e *Element) Li() *Element
- func (e *Element) Link() *Element
- func (e *Element) Main() *Element
- func (e *Element) Map() *Element
- func (e *Element) Mark() *Element
- func (e *Element) Marquee() *Element
- func (e *Element) Math() *Element
- func (e *Element) Menu() *Element
- func (e *Element) Meta() *Element
- func (e *Element) Meter() *Element
- func (e *Element) Nav() *Element
- func (e *Element) Nobr() *Element
- func (e *Element) Noembed() *Element
- func (e *Element) Noframes() *Element
- func (e *Element) Noscript() *Element
- func (e *Element) Object() *Element
- func (e *Element) Ol() *Element
- func (e *Element) Optgroup() *Element
- func (e *Element) Option() *Element
- func (e *Element) Output() *Element
- func (e *Element) P() *Element
- func (e *Element) Param() *Element
- func (e *Element) Picture() *Element
- func (e *Element) Plaintext() *Element
- func (e *Element) Portal() *Element
- func (e *Element) Pre() *Element
- func (e *Element) Progress() *Element
- func (e *Element) Q() *Element
- func (e *Element) Rb() *Element
- func (e *Element) Rp() *Element
- func (e *Element) Rt() *Element
- func (e *Element) Rtc() *Element
- func (e *Element) Ruby() *Element
- func (e *Element) S() *Element
- func (e *Element) Samp() *Element
- func (e *Element) Script() *Element
- func (e *Element) Search() *Element
- func (e *Element) Section() *Element
- func (e *Element) Select() *Element
- func (e *Element) Slot() *Element
- func (e *Element) Small() *Element
- func (e *Element) Source() *Element
- func (e *Element) Span() *Element
- func (e *Element) Strike() *Element
- func (e *Element) Strong() *Element
- func (e *Element) Style() *Element
- func (e *Element) Sub() *Element
- func (e *Element) Summary() *Element
- func (e *Element) Sup() *Element
- func (e *Element) Svg() *Element
- func (e *Element) Table() *Element
- func (e *Element) Tbody() *Element
- func (e *Element) Td() *Element
- func (e *Element) Template() *Element
- func (e *Element) Textarea() *Element
- func (e *Element) Tfoot() *Element
- func (e *Element) Th() *Element
- func (e *Element) Thead() *Element
- func (e *Element) Time() *Element
- func (e *Element) Title() *Element
- func (e *Element) Tr() *Element
- func (e *Element) Track() *Element
- func (e *Element) Tt() *Element
- func (e *Element) U() *Element
- func (e *Element) Ul() *Element
- func (e *Element) Var() *Element
- func (e *Element) Video() *Element
- func (e *Element) Wbr() *Element
- func (e *Element) WithAttrs(attrs ...KeyValue) *Element
- func (e *Element) Xmp() *Element
- type Generator
- type KeyValue
- type NormalTag
- type Tag
- type VoidTag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
type Attribute struct {
Name string
}
Attribute represents a custom allowed attribute configuration.
type Attributes ¶
Attributes represents a map of HTML attribute key-value pairs.
type Element ¶
type Element struct { Tag Tag Attributes Attributes Children []elementI Parent *Element Content string // contains filtered or unexported fields }
Element represents an HTML element with tag, attributes, children, and content.
func (*Element) Attr ¶
Attr sets a single attribute on the current element. For 'class' and 'style' attributes, values are concatenated: - 'class' values are space-separated - 'style' values are semicolon-separated (if no semicolon is added, it will be added for you) For other attributes, the value is replaced.
Examples:
element.Attr("class", "btn").Attr("class", "primary") // Results in: class="btn primary" element.Attr("style", "color: red").Attr("style", "font-size: 12px") // Results in: style="color: red; font-size: 12px;" element.Attr("id", "btn1").Attr("id", "btn2") // Results in: id="btn2"
func (*Element) Blockquote ¶
Blockquote creates a <blockquote> element and adds it to the current element.
func (*Element) Colgroup ¶
Colgroup creates a <colgroup> element and adds it to the current element.
func (*Element) Datalist ¶
Datalist creates a <datalist> element and adds it to the current element.
func (*Element) Fencedframe ¶
Fencedframe creates a <fencedframe> element and adds it to the current element.
func (*Element) Fieldset ¶
Fieldset creates a <fieldset> element and adds it to the current element.
func (*Element) Figcaption ¶
Figcaption creates a <figcaption> element and adds it to the current element.
func (*Element) Frameset ¶
Frameset creates a <frameset> element and adds it to the current element.
func (*Element) Noframes ¶
Noframes creates a <noframes> element and adds it to the current element.
func (*Element) Noscript ¶
Noscript creates a <noscript> element and adds it to the current element.
func (*Element) Optgroup ¶
Optgroup creates a <optgroup> element and adds it to the current element.
func (*Element) Plaintext ¶
Plaintext creates a <plaintext> element and adds it to the current element.
func (*Element) Progress ¶
Progress creates a <progress> element and adds it to the current element.
func (*Element) Template ¶
Template creates a <template> element and adds it to the current element.
func (*Element) Textarea ¶
Textarea creates a <textarea> element and adds it to the current element.
func (*Element) WithAttrs ¶
WithAttrs sets multiple attributes on the current element using KeyValue pairs. For 'class' and 'style' attributes, values are concatenated: - 'class' values are space-separated - 'style' values are semicolon-separated (if no semicolon is added, it will be added for you) For other attributes, the value is replaced.
Example:
element.WithAttrs( KV("class", "btn"), KV("class", "primary"), KV("style", "color: red"), KV("style", "font-size: 12px"), KV("id", "myButton"), ) // Results in: class="btn primary" style="color: red; font-size: 12px;" id="myButton"
type Generator ¶
type Generator struct { Root *Element // contains filtered or unexported fields }
Generator is responsible for generating sanitized HTML.
type NormalTag ¶
type NormalTag string
NormalTag represents standard HTML tags that can have children and content.