Documentation
¶
Index ¶
- func AddNonce(el *Element, len uint8) (string, error)
- func AddSha256HashExternal(el *Element, externalSha256Hash string) (string, error)
- func AddSha256HashInline(el *Element, includeConvenienceIntegrityAttribute bool) (string, error)
- func EscapeAllIntoNewMap(el *Element) map[string]string
- func RenderElement(el *Element) (template.HTML, error)
- func RenderElementToBuilder(el *Element, htmlBuilder *strings.Builder) error
- func RenderModuleScriptToBuilder(src string, htmlBuilder *strings.Builder) error
- type Element
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddSha256HashExternal ¶
func AddSha256HashInline ¶
func EscapeAllIntoNewMap ¶
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 RenderElementToBuilder ¶
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 ¶
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.