bleach

package
v0.0.0-...-60192f8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package bleach is a simple HTML sanitizer tool.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPolicy = New(
	[]*regexp.Regexp{

		regexp.MustCompile(`^(class|style)$`),

		regexp.MustCompile(`^data-`),

		regexp.MustCompile(`^on[a-z]+`),

		regexp.MustCompile(`^(rel|srcset|sizes)$`),
	},
	elementMap,
)

DefaultPolicy is the default bleach policy.

Functions

func SanitizeString

func SanitizeString(s string) string

SanitizeString replaces any control character in a string by a space.

Types

type Policy

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

Policy holds the cleaning rules and provides methods to perform the DOM cleaning.

func New

func New(blockAttrs []*regexp.Regexp, elementMap map[string]string) Policy

New creates a new cleaning policy.

func (Policy) Clean

func (p Policy) Clean(top *html.Node)

Clean cleans removes unwanted tags and attributes from the document.

func (Policy) RemoveEmptyNodes

func (p Policy) RemoveEmptyNodes(top *html.Node)

RemoveEmptyNodes removes the nodes that are empty. empty means: no child nodes, no attributes and no text content.

func (Policy) SetLinkRel

func (p Policy) SetLinkRel(top *html.Node)

SetLinkRel adds a default "rel" attribute on all "a" tags.

Jump to

Keyboard shortcuts

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