sanitize

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeHTMLDocument

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

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

ValidateTipTapDocument checks a decoded TipTap document tree for structural validity (node types, required attributes, depth limits).

Types

type Sanitizer

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

Sanitizer applies the kernel HTML policies: strict plain-text stripping and rich-HTML sanitization with safe links.

func NewSanitizer

func NewSanitizer() *Sanitizer

NewSanitizer builds a Sanitizer with the default policies.

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

SanitizeHTMLWithSafeLinks sanitizes rich HTML and keeps only safe links.

func (Sanitizer) SanitizePlainText

func (s Sanitizer) SanitizePlainText(value string) string

SanitizePlainText strips all HTML, leaving plain text.

func (Sanitizer) SanitizeRichHTML

func (s Sanitizer) SanitizeRichHTML(value string) string

SanitizeRichHTML sanitizes rich HTML while allowing safe inline markup.

Jump to

Keyboard shortcuts

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