Source File
helpers.go
Belonging Package
github.com/microcosm-cc/bluemonday
package bluemonday
import (
)
CellAlign = regexp.MustCompile(`(?i)^(center|justify|left|right|char)$`)
CellVerticalAlign = regexp.MustCompile(`(?i)^(baseline|bottom|middle|top)$`)
Direction = regexp.MustCompile(`(?i)^(rtl|ltr)$`)
ImageAlign = regexp.MustCompile(
`(?i)^(left|right|top|texttop|middle|absmiddle|baseline|bottom|absbottom)$`,
)
Integer = regexp.MustCompile(`^[0-9]+$`)
ISO8601 = regexp.MustCompile(
`^[0-9]{4}(-[0-9]{2}(-[0-9]{2}([ T][0-9]{2}(:[0-9]{2}){1,2}(.[0-9]{1,6})` +
`?Z?([\+-][0-9]{2}:[0-9]{2})?)?)?)?$`,
)
ListType = regexp.MustCompile(`(?i)^(circle|disc|square|a|A|i|I|1)$`)
SpaceSeparatedTokens = regexp.MustCompile(`^([\s\p{L}\p{N}_-]+)$`)
Number = regexp.MustCompile(`^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$`)
NumberOrPercent = regexp.MustCompile(`^[0-9]+[%]?$`)
Paragraph = regexp.MustCompile(`^[\p{L}\p{N}\s\-_',\[\]!\./\\\(\)]*$`)
dataURIImagePrefix = regexp.MustCompile(
`^image/(gif|jpeg|png|webp);base64,`,
)
)
.AllowURLSchemes("mailto", "http", "https")
.AllowAttrs("dir").Matching(Direction).Globally()
.AllowAttrs(
"lang",
).Matching(regexp.MustCompile(`[a-zA-Z]{2,20}`)).Globally()
.AllowAttrs("id").Matching(
regexp.MustCompile(`[a-zA-Z0-9\:\-_\.]+`),
).Globally()
.AllowAttrs("title").Matching(Paragraph).Globally()
}
func ( *Policy) () {
.AllowAttrs("class").Matching(SpaceSeparatedTokens).Globally()
}
func ( *Policy) () {
.AllowAttrs("align").Matching(ImageAlign).OnElements("img")
.AllowAttrs("alt").Matching(Paragraph).OnElements("img")
.AllowAttrs("height", "width").Matching(NumberOrPercent).OnElements("img")
.AllowStandardURLs()
.AllowAttrs("src").OnElements("img")
}
func ( *Policy) () {
.AllowURLSchemeWithCustomPolicy(
"data",
func( *url.URL) ( bool) {
if .RawQuery != "" || .Fragment != "" {
return false
}
:= dataURIImagePrefix.FindString(.Opaque)
if == "" {
return false
}
, := base64.StdEncoding.DecodeString(.Opaque[len():])
if != nil {
return false
}
return true
},
)
}
.AllowAttrs("type").Matching(ListType).OnElements("ol", "ul")
.AllowAttrs("type").Matching(ListType).OnElements("li")
.AllowAttrs("value").Matching(Integer).OnElements("li")
.AllowElements("dl", "dt", "dd")
}
func ( *Policy) () {
.AllowAttrs("height", "width").Matching(NumberOrPercent).OnElements("table")
.AllowAttrs("summary").Matching(Paragraph).OnElements("table")
.AllowElements("caption")
.AllowAttrs("align").Matching(CellAlign).OnElements("col", "colgroup")
.AllowAttrs("height", "width").Matching(
NumberOrPercent,
).OnElements("col", "colgroup")
.AllowAttrs("span").Matching(Integer).OnElements("colgroup", "col")
.AllowAttrs("valign").Matching(
CellVerticalAlign,
).OnElements("col", "colgroup")
.AllowAttrs("align").Matching(CellAlign).OnElements("thead", "tr")
.AllowAttrs("valign").Matching(CellVerticalAlign).OnElements("thead", "tr")
.AllowAttrs("abbr").Matching(Paragraph).OnElements("td", "th")
.AllowAttrs("align").Matching(CellAlign).OnElements("td", "th")
.AllowAttrs("colspan", "rowspan").Matching(Integer).OnElements("td", "th")
.AllowAttrs("headers").Matching(
SpaceSeparatedTokens,
).OnElements("td", "th")
.AllowAttrs("height", "width").Matching(
NumberOrPercent,
).OnElements("td", "th")
.AllowAttrs(
"scope",
).Matching(
regexp.MustCompile(`(?i)(?:row|col)(?:group)?`),
).OnElements("td", "th")
.AllowAttrs("valign").Matching(CellVerticalAlign).OnElements("td", "th")
.AllowAttrs("nowrap").Matching(
regexp.MustCompile(`(?i)|nowrap`),
).OnElements("td", "th")
.AllowAttrs("align").Matching(CellAlign).OnElements("tbody", "tfoot")
.AllowAttrs("valign").Matching(
CellVerticalAlign,
).OnElements("tbody", "tfoot")
![]() |
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. |