htmlsimple

package module
v0.0.0-...-71bd988 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT Imports: 3 Imported by: 0

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

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

type Attributes map[string][]string

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) A

func (e *Element) A() *Element

A creates a <a> element and adds it to the current element.

func (*Element) Abbr

func (e *Element) Abbr() *Element

Abbr creates a <abbr> element and adds it to the current element.

func (*Element) Acronym

func (e *Element) Acronym() *Element

Acronym creates a <acronym> element and adds it to the current element.

func (*Element) Add

func (e *Element) Add(tag NormalTag) *Element

Add creates and adds a child NormalTag element to the current element.

func (*Element) AddString

func (e *Element) AddString(content string) *Element

AddString adds sanitized text content to the current element.

func (*Element) AddVoid

func (e *Element) AddVoid(tag VoidTag) *Element

AddVoid creates and adds a child VoidTag element to the current element.

func (*Element) Address

func (e *Element) Address() *Element

Address creates a <address> element and adds it to the current element.

func (*Element) Area

func (e *Element) Area() *Element

Area creates a void <area> element and adds it to the current element.

func (*Element) Article

func (e *Element) Article() *Element

Article creates a <article> element and adds it to the current element.

func (*Element) Aside

func (e *Element) Aside() *Element

Aside creates a <aside> element and adds it to the current element.

func (*Element) Attr

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

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) Audio

func (e *Element) Audio() *Element

Audio creates a <audio> element and adds it to the current element.

func (*Element) B

func (e *Element) B() *Element

B creates a <b> element and adds it to the current element.

func (*Element) Base

func (e *Element) Base() *Element

Base creates a void <base> element and adds it to the current element.

func (*Element) Bdi

func (e *Element) Bdi() *Element

Bdi creates a <bdi> element and adds it to the current element.

func (*Element) Bdo

func (e *Element) Bdo() *Element

Bdo creates a <bdo> element and adds it to the current element.

func (*Element) Big

func (e *Element) Big() *Element

Big creates a <big> element and adds it to the current element.

func (*Element) Blockquote

func (e *Element) Blockquote() *Element

Blockquote creates a <blockquote> element and adds it to the current element.

func (*Element) Body

func (e *Element) Body() *Element

Body creates a <body> element and adds it to the current element.

func (*Element) Br

func (e *Element) Br() *Element

Br creates a void <br> element and adds it to the current element.

func (*Element) Button

func (e *Element) Button() *Element

Button creates a <button> element and adds it to the current element.

func (*Element) Canvas

func (e *Element) Canvas() *Element

Canvas creates a <canvas> element and adds it to the current element.

func (*Element) Caption

func (e *Element) Caption() *Element

Caption creates a <caption> element and adds it to the current element.

func (*Element) Center

func (e *Element) Center() *Element

Center creates a <center> element and adds it to the current element.

func (*Element) Cite

func (e *Element) Cite() *Element

Cite creates a <cite> element and adds it to the current element.

func (*Element) Code

func (e *Element) Code() *Element

Code creates a <code> element and adds it to the current element.

func (*Element) Col

func (e *Element) Col() *Element

Col creates a void <col> element and adds it to the current element.

func (*Element) Colgroup

func (e *Element) Colgroup() *Element

Colgroup creates a <colgroup> element and adds it to the current element.

func (*Element) Data

func (e *Element) Data() *Element

Data creates a <data> element and adds it to the current element.

func (*Element) Datalist

func (e *Element) Datalist() *Element

Datalist creates a <datalist> element and adds it to the current element.

func (*Element) Dd

func (e *Element) Dd() *Element

Dd creates a <dd> element and adds it to the current element.

func (*Element) Del

func (e *Element) Del() *Element

Del creates a <del> element and adds it to the current element.

func (*Element) Details

func (e *Element) Details() *Element

Details creates a <details> element and adds it to the current element.

func (*Element) Dfn

func (e *Element) Dfn() *Element

Dfn creates a <dfn> element and adds it to the current element.

func (*Element) Dialog

func (e *Element) Dialog() *Element

Dialog creates a <dialog> element and adds it to the current element.

func (*Element) Dir

func (e *Element) Dir() *Element

Dir creates a <dir> element and adds it to the current element.

func (*Element) Div

func (e *Element) Div() *Element

Div creates a <div> element and adds it to the current element.

func (*Element) Dl

func (e *Element) Dl() *Element

Dl creates a <dl> element and adds it to the current element.

func (*Element) Dt

func (e *Element) Dt() *Element

Dt creates a <dt> element and adds it to the current element.

func (*Element) Em

func (e *Element) Em() *Element

Em creates a <em> element and adds it to the current element.

func (*Element) Embed

func (e *Element) Embed() *Element

Embed creates a void <embed> element and adds it to the current element.

func (*Element) Fencedframe

func (e *Element) Fencedframe() *Element

Fencedframe creates a <fencedframe> element and adds it to the current element.

func (*Element) Fieldset

func (e *Element) Fieldset() *Element

Fieldset creates a <fieldset> element and adds it to the current element.

func (*Element) Figcaption

func (e *Element) Figcaption() *Element

Figcaption creates a <figcaption> element and adds it to the current element.

func (*Element) Figure

func (e *Element) Figure() *Element

Figure creates a <figure> element and adds it to the current element.

func (*Element) Font

func (e *Element) Font() *Element

Font creates a <font> element and adds it to the current element.

func (*Element) Footer

func (e *Element) Footer() *Element

Footer creates a <footer> element and adds it to the current element.

func (*Element) Form

func (e *Element) Form() *Element

Form creates a <form> element and adds it to the current element.

func (*Element) Frame

func (e *Element) Frame() *Element

Frame creates a <frame> element and adds it to the current element.

func (*Element) Frameset

func (e *Element) Frameset() *Element

Frameset creates a <frameset> element and adds it to the current element.

func (*Element) H1

func (e *Element) H1() *Element

H1 creates a <h1> element and adds it to the current element.

func (*Element) Head

func (e *Element) Head() *Element

Head creates a <head> element and adds it to the current element.

func (*Element) Header

func (e *Element) Header() *Element

Header creates a <header> element and adds it to the current element.

func (*Element) Hgroup

func (e *Element) Hgroup() *Element

Hgroup creates a <hgroup> element and adds it to the current element.

func (*Element) Hr

func (e *Element) Hr() *Element

Hr creates a void <hr> element and adds it to the current element.

func (*Element) Html

func (e *Element) Html() *Element

Html creates a <html> element and adds it to the current element.

func (*Element) I

func (e *Element) I() *Element

I creates a <i> element and adds it to the current element.

func (*Element) Iframe

func (e *Element) Iframe() *Element

Iframe creates a <iframe> element and adds it to the current element.

func (*Element) Img

func (e *Element) Img() *Element

Img creates a void <img> element and adds it to the current element.

func (*Element) Input

func (e *Element) Input() *Element

Input creates a void <input> element and adds it to the current element.

func (*Element) Ins

func (e *Element) Ins() *Element

Ins creates a <ins> element and adds it to the current element.

func (*Element) Kbd

func (e *Element) Kbd() *Element

Kbd creates a <kbd> element and adds it to the current element.

func (*Element) Label

func (e *Element) Label() *Element

Label creates a <label> element and adds it to the current element.

func (*Element) Legend

func (e *Element) Legend() *Element

Legend creates a <legend> element and adds it to the current element.

func (*Element) Li

func (e *Element) Li() *Element

Li creates a <li> element and adds it to the current element.

func (e *Element) Link() *Element

Link creates a void <link> element and adds it to the current element.

func (*Element) Main

func (e *Element) Main() *Element

Main creates a <main> element and adds it to the current element.

func (*Element) Map

func (e *Element) Map() *Element

Map creates a <map> element and adds it to the current element.

func (*Element) Mark

func (e *Element) Mark() *Element

Mark creates a <mark> element and adds it to the current element.

func (*Element) Marquee

func (e *Element) Marquee() *Element

Marquee creates a <marquee> element and adds it to the current element.

func (*Element) Math

func (e *Element) Math() *Element

Math creates a <math> element and adds it to the current element.

func (*Element) Menu

func (e *Element) Menu() *Element

Menu creates a <menu> element and adds it to the current element.

func (*Element) Meta

func (e *Element) Meta() *Element

Meta creates a void <meta> element and adds it to the current element.

func (*Element) Meter

func (e *Element) Meter() *Element

Meter creates a <meter> element and adds it to the current element.

func (*Element) Nav

func (e *Element) Nav() *Element

Nav creates a <nav> element and adds it to the current element.

func (*Element) Nobr

func (e *Element) Nobr() *Element

Nobr creates a <nobr> element and adds it to the current element.

func (*Element) Noembed

func (e *Element) Noembed() *Element

Noembed creates a <noembed> element and adds it to the current element.

func (*Element) Noframes

func (e *Element) Noframes() *Element

Noframes creates a <noframes> element and adds it to the current element.

func (*Element) Noscript

func (e *Element) Noscript() *Element

Noscript creates a <noscript> element and adds it to the current element.

func (*Element) Object

func (e *Element) Object() *Element

Object creates a <object> element and adds it to the current element.

func (*Element) Ol

func (e *Element) Ol() *Element

Ol creates a <ol> element and adds it to the current element.

func (*Element) Optgroup

func (e *Element) Optgroup() *Element

Optgroup creates a <optgroup> element and adds it to the current element.

func (*Element) Option

func (e *Element) Option() *Element

Option creates a <option> element and adds it to the current element.

func (*Element) Output

func (e *Element) Output() *Element

Output creates a <output> element and adds it to the current element.

func (*Element) P

func (e *Element) P() *Element

P creates a <p> element and adds it to the current element.

func (*Element) Param

func (e *Element) Param() *Element

Param creates a void <param> element and adds it to the current element.

func (*Element) Picture

func (e *Element) Picture() *Element

Picture creates a <picture> element and adds it to the current element.

func (*Element) Plaintext

func (e *Element) Plaintext() *Element

Plaintext creates a <plaintext> element and adds it to the current element.

func (*Element) Portal

func (e *Element) Portal() *Element

Portal creates a <portal> element and adds it to the current element.

func (*Element) Pre

func (e *Element) Pre() *Element

Pre creates a <pre> element and adds it to the current element.

func (*Element) Progress

func (e *Element) Progress() *Element

Progress creates a <progress> element and adds it to the current element.

func (*Element) Q

func (e *Element) Q() *Element

Q creates a <q> element and adds it to the current element.

func (*Element) Rb

func (e *Element) Rb() *Element

Rb creates a <rb> element and adds it to the current element.

func (*Element) Rp

func (e *Element) Rp() *Element

Rp creates a <rp> element and adds it to the current element.

func (*Element) Rt

func (e *Element) Rt() *Element

Rt creates a <rt> element and adds it to the current element.

func (*Element) Rtc

func (e *Element) Rtc() *Element

Rtc creates a <rtc> element and adds it to the current element.

func (*Element) Ruby

func (e *Element) Ruby() *Element

Ruby creates a <ruby> element and adds it to the current element.

func (*Element) S

func (e *Element) S() *Element

S creates a <s> element and adds it to the current element.

func (*Element) Samp

func (e *Element) Samp() *Element

Samp creates a <samp> element and adds it to the current element.

func (*Element) Script

func (e *Element) Script() *Element

Script creates a <script> element and adds it to the current element.

func (*Element) Search

func (e *Element) Search() *Element

Search creates a <search> element and adds it to the current element.

func (*Element) Section

func (e *Element) Section() *Element

Section creates a <section> element and adds it to the current element.

func (*Element) Select

func (e *Element) Select() *Element

Select creates a <select> element and adds it to the current element.

func (*Element) Slot

func (e *Element) Slot() *Element

Slot creates a <slot> element and adds it to the current element.

func (*Element) Small

func (e *Element) Small() *Element

Small creates a <small> element and adds it to the current element.

func (*Element) Source

func (e *Element) Source() *Element

Source creates a void <source> element and adds it to the current element.

func (*Element) Span

func (e *Element) Span() *Element

Span creates a <span> element and adds it to the current element.

func (*Element) Strike

func (e *Element) Strike() *Element

Strike creates a <strike> element and adds it to the current element.

func (*Element) Strong

func (e *Element) Strong() *Element

Strong creates a <strong> element and adds it to the current element.

func (*Element) Style

func (e *Element) Style() *Element

Style creates a <style> element and adds it to the current element.

func (*Element) Sub

func (e *Element) Sub() *Element

Sub creates a <sub> element and adds it to the current element.

func (*Element) Summary

func (e *Element) Summary() *Element

Summary creates a <summary> element and adds it to the current element.

func (*Element) Sup

func (e *Element) Sup() *Element

Sup creates a <sup> element and adds it to the current element.

func (*Element) Svg

func (e *Element) Svg() *Element

Svg creates a <svg> element and adds it to the current element.

func (*Element) Table

func (e *Element) Table() *Element

Table creates a <table> element and adds it to the current element.

func (*Element) Tbody

func (e *Element) Tbody() *Element

Tbody creates a <tbody> element and adds it to the current element.

func (*Element) Td

func (e *Element) Td() *Element

Td creates a <td> element and adds it to the current element.

func (*Element) Template

func (e *Element) Template() *Element

Template creates a <template> element and adds it to the current element.

func (*Element) Textarea

func (e *Element) Textarea() *Element

Textarea creates a <textarea> element and adds it to the current element.

func (*Element) Tfoot

func (e *Element) Tfoot() *Element

Tfoot creates a <tfoot> element and adds it to the current element.

func (*Element) Th

func (e *Element) Th() *Element

Th creates a <th> element and adds it to the current element.

func (*Element) Thead

func (e *Element) Thead() *Element

Thead creates a <thead> element and adds it to the current element.

func (*Element) Time

func (e *Element) Time() *Element

Time creates a <time> element and adds it to the current element.

func (*Element) Title

func (e *Element) Title() *Element

Title creates a <title> element and adds it to the current element.

func (*Element) Tr

func (e *Element) Tr() *Element

Tr creates a <tr> element and adds it to the current element.

func (*Element) Track

func (e *Element) Track() *Element

Track creates a void <track> element and adds it to the current element.

func (*Element) Tt

func (e *Element) Tt() *Element

Tt creates a <tt> element and adds it to the current element.

func (*Element) U

func (e *Element) U() *Element

U creates a <u> element and adds it to the current element.

func (*Element) Ul

func (e *Element) Ul() *Element

Ul creates a <ul> element and adds it to the current element.

func (*Element) Var

func (e *Element) Var() *Element

Var creates a <var> element and adds it to the current element.

func (*Element) Video

func (e *Element) Video() *Element

Video creates a <video> element and adds it to the current element.

func (*Element) Wbr

func (e *Element) Wbr() *Element

Wbr creates a void <wbr> element and adds it to the current element.

func (*Element) WithAttrs

func (e *Element) WithAttrs(attrs ...KeyValue) *Element

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"

func (*Element) Xmp

func (e *Element) Xmp() *Element

Xmp creates a <xmp> element and adds it to the current element.

type Generator

type Generator struct {
	Root *Element
	// contains filtered or unexported fields
}

Generator is responsible for generating sanitized HTML.

func New

func New(allowedAttributesCustom []Attribute) *Generator

New initializes a new Generator with default allowed attributes and sanitization functions.

func (*Generator) Generate

func (g *Generator) Generate() string

Generate returns the complete sanitized HTML string.

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

KeyValue is a helper struct for setting attributes.

func KV

func KV(key, value string) KeyValue

KV creates a KeyValue pair.

type NormalTag

type NormalTag string

NormalTag represents standard HTML tags that can have children and content.

type Tag

type Tag interface {
	// contains filtered or unexported methods
}

Tag interface represents an HTML tag with a name.

type VoidTag

type VoidTag string

VoidTag represents self-closing HTML tags that cannot have children or content.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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