Source File
stylesheet.go
Belonging Package
github.com/google/safehtml
package safehtml
import (
)
func ( stringConstant) StyleSheet {
return StyleSheet{string()}
}
func ( string, Style) (StyleSheet, error) {
if strings.ContainsRune(, '<') {
return StyleSheet{}, fmt.Errorf("selector %q contains '<'", )
}
:= cssStringPattern.ReplaceAllString(, "")
if := invalidCSSSelectorRune.FindStringSubmatch(); != nil {
return StyleSheet{}, fmt.Errorf("selector %q contains %q, which is disallowed outside of CSS strings", , [0])
}
if !hasBalancedBrackets() {
return StyleSheet{}, fmt.Errorf("selector %q contains unbalanced () or [] brackets", )
}
return StyleSheet{fmt.Sprintf("%s{%s}", , .String())}, nil
}
cssStringPattern = regexp.MustCompile(
`"([^"\r\n\f\\]|\\[\s\S])*"|` + // Double-quoted string literal
`'([^'\r\n\f\\]|\\[\s\S])*'`) // Single-quoted string literal
invalidCSSSelectorRune = regexp.MustCompile(`[^-_a-zA-Z0-9#.:* ,>+~[\]()=^$|]`)
)
var matchingBrackets = map[byte]byte{
')': '(',
']': '[',
}
func ( StyleSheet) () string {
return .str
![]() |
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. |