htmlutil

package
v0.0.86 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddNonce

func AddNonce(el *Element, len uint8) (string, error)

func AddSha256HashExternal

func AddSha256HashExternal(el *Element, externalSha256Hash string) (string, error)

func AddSha256HashInline

func AddSha256HashInline(el *Element, includeConvenienceIntegrityAttribute bool) (string, error)

func EscapeAllIntoNewMap

func EscapeAllIntoNewMap(el *Element) map[string]string

EscapeAllIntoNewMap returns a new TrustedAttributes map containing both the original TrustedAttributes items and the Attributes items, with the values escaped. In the case of a key collision, the value from the original TrustedAttributes map will be used.

func RenderElement

func RenderElement(el *Element) (template.HTML, error)

func RenderElementToBuilder

func RenderElementToBuilder(el *Element, htmlBuilder *strings.Builder) error

func RenderModuleScriptToBuilder added in v0.0.84

func RenderModuleScriptToBuilder(src string, htmlBuilder *strings.Builder) error

Types

type Element

type Element struct {
	Tag        string            `json:"tag,omitempty"`
	Attributes map[string]string `json:"attributes,omitempty"`
	// TrustedAttributes are attributes whose values are safe to render as-is.
	// This means you either know the value is safe (because you control it)
	// or you have escaped it already. If you aren't sure, use the Attributes
	// field instead.
	TrustedAttributes map[string]string `json:"safeAttributes,omitempty"`
	BooleanAttributes []string          `json:"booleanAttributes,omitempty"`
	InnerHTML         template.HTML     `json:"innerHTML,omitempty"`
	SelfClosing       bool              `json:"-"`
}

Element is a structure for defining HTML elements. For both Attributes and TrustedAttributes, consumers are in charge of making sure keys are safe. This means that if you are using user input as a key, you need to escape it before passing it to this package. This package will only escape the values of the Attributes map (and not the TrustedAttributes map).

func EscapeIntoTrusted

func EscapeIntoTrusted(el *Element) Element

EscapeIntoTrusted returns a new Element identical to the provided Element, but with the values of the Attributes map escaped and moved to the TrustedAttributes map. In the case of a key collision, the value from the original TrustedAttributes map will be used.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳