sanitize

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeHTMLDocument added in v0.6.0

func SanitizeHTMLDocument(html string, iframeAllowlist ...string) string

SanitizeHTMLDocument sanitizes an HTML document body using the permissive HTML document policy. The iframeAllowlist controls which domains are allowed in iframe src attributes.

func ValidateHTMLDocument added in v0.6.0

func ValidateHTMLDocument(html string) error

ValidateHTMLDocument validates that the HTML document is non-empty and does not contain script tags or event handler attributes. It returns an error if the document is invalid.

func ValidateTipTapDocument

func ValidateTipTapDocument(doc map[string]any) error

Types

type Sanitizer

type Sanitizer struct {
	// contains filtered or unexported fields
}

func NewSanitizer

func NewSanitizer() *Sanitizer

func (Sanitizer) ContainsHTML

func (s Sanitizer) ContainsHTML(value string) bool

ContainsHTML reports whether value contains an actual HTML tag (an opening "<" immediately followed by a tag-name letter, a "/" for closing tags, or a "!" for comments/DOCTYPE). It deliberately does NOT treat a bare "&" or a straight "'" as HTML: bluemonday's strict policy escapes those to "&amp;"/"&#39;", so a previous "did the sanitizer change the input?" heuristic false-positived on real titles like "Install & first content" or "roaster's". Plain text that merely contains an ampersand, an apostrophe, or a math "<" is left alone.

func (s Sanitizer) SanitizeHTMLWithSafeLinks(html string) string

func (Sanitizer) SanitizePlainText

func (s Sanitizer) SanitizePlainText(value string) string

func (Sanitizer) SanitizeRichHTML

func (s Sanitizer) SanitizeRichHTML(value string) string

Jump to

Keyboard shortcuts

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