Source File
render.go
Belonging Package
golang.org/x/net/html
var plaintextAbort = errors.New("html: internal error (plaintext abort)")
func ( writer, *Node) error {
:= render1(, )
if == plaintextAbort {
= nil
}
return
}
switch .Type {
case ErrorNode:
return errors.New("html: cannot render an ErrorNode node")
case TextNode:
return escape(, .Data)
case DocumentNode:
for := .FirstChild; != nil; = .NextSibling {
if := (, ); != nil {
return
}
}
return nil
case CommentNode:
if , := .WriteString("<!--"); != nil {
return
}
if , := .WriteString(.Data); != nil {
return
}
if , := .WriteString("-->"); != nil {
return
}
return nil
case DoctypeNode:
if , := .WriteString("<!DOCTYPE "); != nil {
return
}
if , := .WriteString(.Data); != nil {
return
}
if .Attr != nil {
var , string
for , := range .Attr {
switch .Key {
case "public":
= .Val
case "system":
= .Val
}
}
if != "" {
if , := .WriteString(" PUBLIC "); != nil {
return
}
if := writeQuoted(, ); != nil {
return
}
if != "" {
if := .WriteByte(' '); != nil {
return
}
if := writeQuoted(, ); != nil {
return
}
}
} else if != "" {
if , := .WriteString(" SYSTEM "); != nil {
return
}
if := writeQuoted(, ); != nil {
return
}
}
}
return .WriteByte('>')
case RawNode:
, := .WriteString(.Data)
return
default:
return errors.New("html: unknown node type")
}
if := .WriteByte('<'); != nil {
return
}
if , := .WriteString(.Data); != nil {
return
}
for , := range .Attr {
if := .WriteByte(' '); != nil {
return
}
if .Namespace != "" {
if , := .WriteString(.Namespace); != nil {
return
}
if := .WriteByte(':'); != nil {
return
}
}
if , := .WriteString(.Key); != nil {
return
}
if , := .WriteString(`="`); != nil {
return
}
if := escape(, .Val); != nil {
return
}
if := .WriteByte('"'); != nil {
return
}
}
if voidElements[.Data] {
if .FirstChild != nil {
return fmt.Errorf("html: void element <%s> has child nodes", .Data)
}
, := .WriteString("/>")
return
}
if := .WriteByte('>'); != nil {
return
}
switch .Data {
case "iframe", "noembed", "noframes", "noscript", "plaintext", "script", "style", "xmp":
for := .FirstChild; != nil; = .NextSibling {
if .Type == TextNode {
if , := .WriteString(.Data); != nil {
return
}
} else {
if := (, ); != nil {
return
}
}
}
return plaintextAbort
}
default:
for := .FirstChild; != nil; = .NextSibling {
if := (, ); != nil {
return
}
}
}
if , := .WriteString("</"); != nil {
return
}
if , := .WriteString(.Data); != nil {
return
}
return .WriteByte('>')
}
var voidElements = map[string]bool{
"area": true,
"base": true,
"br": true,
"col": true,
"embed": true,
"hr": true,
"img": true,
"input": true,
"keygen": true, // "keygen" has been removed from the spec, but are kept here for backwards compatibility.
"link": true,
"meta": true,
"param": true,
"source": true,
"track": true,
"wbr": true,
![]() |
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. |