Golang html/template.CSS type examples
package html/template
CSS encapsulates known safe content that matches any of:
The CSS3 stylesheet production, such as
p { color: purple }
.The CSS3 rule production, such as
a[href=~"https:"].foo#bar
.CSS3 declaration productions, such as
color: red; margin: 2px
.The CSS3 value production, such as
rgba(0, 0, 255, 127)
.
Golang html/template.CSS type usage examples
Example 1:
func colorNick(s string) template.CSS { // <-- here
hue := uint(0)
for _, c := range s {
hue *= 17
hue += uint(c)
}
style := fmt.Sprintf("color: hsl(%d, 40%%, 50%%)", hue%360)
return template.CSS(style)
}
Example 2:
inputs := []interface{}{
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f" +
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
` !"#$%&'()*+,-./` +
`0123456789:;<=>?` +
`@ABCDEFGHIJKLMNO` +
`PQRSTUVWXYZ[\]^_` +
"`abcdefghijklmno" +
"pqrstuvwxyz{|}~\x7f" +
"\u00A0\u0100\u2028\u2029\ufeff\ufdec\ufffd\uffff\U0001D11E" +
"&%22\\",
CSS(`a[href =~ "//example.com"]#foo`), // <---- here
HTML(`Hello, <b>World</b> &tc!`),
HTMLAttr(` dir="ltr"`),
JS(`c && alert("Hello, World!");`),
JSStr(`Hello, World & O'Reilly\x21`),
URL(`greeting=H%69&addressee=(World)`),
}
References :
https://github.com/remyoudompheng/go-misc/blob/master/webtoys/irc/irc.go
Advertisement
Something interesting
Tutorials
+7.9k Javascript : Put image into Chrome browser's console
+16.9k Golang : How to generate QR codes?
+12.4k Elastic Search : Return all records (higher than default 10)
+19.9k Golang : Measure http.Get() execution time
+10.3k Golang : Convert file unix timestamp to UTC time example
+10.6k Golang : ISO8601 Duration Parser example
+9k Golang : Get SPF and DMARC from email headers to fight spam
+10.5k Generate Random number with math/rand in Go
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+16k Golang : Read large file with bufio.Scanner cause token too long error
+7.5k Golang : Get YouTube playlist
+10.6k Golang : How to delete element(data) from map ?