sanitize

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 6 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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. <style> blocks are stripped for every author — page CSS belongs in the theme. 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