Standard library / html/template
html/template.HTMLAttr
Trusted HTML attribute syntax; only use developer-controlled attributes. Expected stdout: '<p class="fixed">ok</p>\n'.
Formal Syntax & Structure
go syntaxgo
type HTMLAttr stringWorking Example
Example Snippetgo
package main
import ( "fmt" "html/template" "os")
func check(e error) { if e != nil { panic(e) }}
func main() { t := template.Must(template.New("x").Parse("<p {{.}}>ok</p>")) check(t.Execute(os.Stdout, template.HTMLAttr("class=\"fixed\""))) fmt.Println()}