Source File
policy.go
Belonging Package
github.com/microcosm-cc/bluemonday
package bluemonday
import (
)
type Policy struct {
elsAndAttrs map[string]map[string]attrPolicy
setOfElementsAllowedWithoutAttrs map[string]struct{}
setOfElementsToSkipContent map[string]struct{}
}
type attrPolicy struct {
func ( *Policy) () {
if !.initialized {
.elsAndAttrs = make(map[string]map[string]attrPolicy)
.globalAttrs = make(map[string]attrPolicy)
.allowURLSchemes = make(map[string]urlPolicy)
.setOfElementsAllowedWithoutAttrs = make(map[string]struct{})
.setOfElementsToSkipContent = make(map[string]struct{})
.initialized = true
}
}
func () *Policy {
:= Policy{}
.addDefaultElementsWithoutAttrs()
.addDefaultSkipElementContent()
return &
}
func ( *Policy) ( ...string) *attrPolicyBuilder {
.init()
:= attrPolicyBuilder{
p: ,
allowEmpty: false,
}
for , := range {
.attrNames = append(.attrNames, strings.ToLower())
}
return &
}
func ( *Policy) () {
.allowDataAttributes = true
}
func ( *Policy) () *attrPolicyBuilder {
.init()
:= attrPolicyBuilder{
p: ,
allowEmpty: true,
}
return &
}
func ( *attrPolicyBuilder) () *attrPolicyBuilder {
.allowEmpty = true
return
}
func ( *attrPolicyBuilder) ( *regexp.Regexp) *attrPolicyBuilder {
.regexp =
return
}
func ( *attrPolicyBuilder) ( ...string) *Policy {
for , := range {
= strings.ToLower()
for , := range .attrNames {
if , := .p.elsAndAttrs[]; ! {
.p.elsAndAttrs[] = make(map[string]attrPolicy)
}
:= attrPolicy{}
if .regexp != nil {
.regexp = .regexp
}
.p.elsAndAttrs[][] =
}
if .allowEmpty {
.p.setOfElementsAllowedWithoutAttrs[] = struct{}{}
if , := .p.elsAndAttrs[]; ! {
.p.elsAndAttrs[] = make(map[string]attrPolicy)
}
}
}
return .p
}
func ( *attrPolicyBuilder) () *Policy {
for , := range .attrNames {
if , := .p.globalAttrs[]; ! {
.p.globalAttrs[] = attrPolicy{}
}
:= attrPolicy{}
if .regexp != nil {
.regexp = .regexp
}
.p.globalAttrs[] =
}
return .p
}
func ( *Policy) ( ...string) *Policy {
.init()
for , := range {
= strings.ToLower()
if , := .elsAndAttrs[]; ! {
.elsAndAttrs[] = make(map[string]attrPolicy)
}
}
return
}
func ( *Policy) ( bool) *Policy {
.requireNoFollow =
.requireParseableURLs = true
return
}
func ( *Policy) ( bool) *Policy {
.requireNoFollowFullyQualifiedLinks =
.requireParseableURLs = true
return
}
func ( *Policy) ( bool) *Policy {
.addTargetBlankToFullyQualifiedLinks =
.requireParseableURLs = true
return
}
func ( *Policy) ( bool) *Policy {
.requireParseableURLs =
return
}
func ( *Policy) ( bool) *Policy {
.RequireParseableURLs(true)
.allowRelativeURLs =
return
}
.allowURLSchemes[] = nil
}
return
}
func ( *Policy) ( ...string) *Policy {
.init()
for , := range {
= strings.ToLower()
if , := .setOfElementsToSkipContent[]; ! {
.setOfElementsToSkipContent[] = struct{}{}
}
}
return
}
func ( *Policy) () {
.init()
.setOfElementsAllowedWithoutAttrs["abbr"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["acronym"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["address"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["article"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["aside"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["audio"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["b"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["bdi"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["blockquote"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["body"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["br"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["button"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["canvas"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["caption"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["center"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["cite"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["code"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["col"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["colgroup"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["datalist"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["dd"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["del"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["details"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["dfn"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["div"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["dl"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["dt"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["em"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["fieldset"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["figcaption"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["figure"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["footer"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["h1"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["h2"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["h3"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["h4"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["h5"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["h6"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["head"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["header"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["hgroup"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["hr"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["html"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["i"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["ins"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["kbd"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["li"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["mark"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["marquee"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["nav"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["ol"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["optgroup"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["option"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["p"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["pre"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["q"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["rp"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["rt"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["ruby"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["s"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["samp"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["script"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["section"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["select"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["small"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["span"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["strike"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["strong"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["style"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["sub"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["summary"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["sup"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["svg"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["table"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["tbody"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["td"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["textarea"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["tfoot"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["th"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["thead"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["title"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["time"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["tr"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["tt"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["u"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["ul"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["var"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["video"] = struct{}{}
.setOfElementsAllowedWithoutAttrs["wbr"] = struct{}{}
}
func ( *Policy) () {
.init()
.setOfElementsToSkipContent["frame"] = struct{}{}
.setOfElementsToSkipContent["frameset"] = struct{}{}
.setOfElementsToSkipContent["iframe"] = struct{}{}
.setOfElementsToSkipContent["noembed"] = struct{}{}
.setOfElementsToSkipContent["noframes"] = struct{}{}
.setOfElementsToSkipContent["noscript"] = struct{}{}
.setOfElementsToSkipContent["nostyle"] = struct{}{}
.setOfElementsToSkipContent["object"] = struct{}{}
.setOfElementsToSkipContent["script"] = struct{}{}
.setOfElementsToSkipContent["style"] = struct{}{}
.setOfElementsToSkipContent["title"] = struct{}{}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |