-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgsoup.go
43 lines (36 loc) · 1.37 KB
/
gsoup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package gsoup
import "golang.org/x/net/html/atom"
// NewEmptyCleaner creates a cleaner with no allowed tags
func NewEmptyCleaner() Cleaner {
return &cleaner{w: whitelist{}}
}
// NewSimpleCleaner creates a Cleaner with the default simple whitelist
// This whitelist mirrors Jsoup's simple whitelist
func NewSimpleCleaner() Cleaner {
return &cleaner{w: cloneWhitelist(simpleTextWhitelist)}
}
// NewBasicCleaner creates a Cleaner with the default basic whitelist
// This whitelist mirrors Jsoup's basic whitelist
func NewBasicCleaner() Cleaner {
return &cleaner{w: cloneWhitelist(basicWhitelist)}
}
// NewBasicCleanerWithImages creates a Cleaner with the default basic whitelist
// that also allows <img> with http or https protocols.
// This whitelist mirrors Jsoup's basic whitelist with images.
func NewBasicCleanerWithImages() Cleaner {
return &cleaner{w: cloneWhitelist(basicWhitelistWithImages)}
}
// NewRelaxedCleaner creates a Cleaner with the default relaxed whitelist
// This whitelist mirrors Jsoup's relaxed whitelist
func NewRelaxedCleaner() Cleaner {
return &cleaner{w: cloneWhitelist(relaxedWhitelist)}
}
// T is a shorthand method for creating a new Tagdef
func T(tag atom.Atom, attrs ...string) (def *Tagdef) {
def = &Tagdef{Tag: tag}
def.AllowedAttrs = make(Attrset)
for _, attr := range attrs {
def.AllowedAttrs[normalizeAttrKey(attr)] = struct{}{}
}
return def
}