summaryrefslogtreecommitdiff
path: root/libgo/go/exp/html/render.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/exp/html/render.go')
-rw-r--r--libgo/go/exp/html/render.go32
1 files changed, 13 insertions, 19 deletions
diff --git a/libgo/go/exp/html/render.go b/libgo/go/exp/html/render.go
index 07859faa7dd..65b10046a48 100644
--- a/libgo/go/exp/html/render.go
+++ b/libgo/go/exp/html/render.go
@@ -73,7 +73,7 @@ func render1(w writer, n *Node) error {
case TextNode:
return escape(w, n.Data)
case DocumentNode:
- for _, c := range n.Child {
+ for c := n.FirstChild; c != nil; c = c.NextSibling {
if err := render1(w, c); err != nil {
return err
}
@@ -171,7 +171,7 @@ func render1(w writer, n *Node) error {
}
}
if voidElements[n.Data] {
- if len(n.Child) != 0 {
+ if n.FirstChild != nil {
return fmt.Errorf("html: void element <%s> has child nodes", n.Data)
}
_, err := w.WriteString("/>")
@@ -182,7 +182,7 @@ func render1(w writer, n *Node) error {
}
// Add initial newline where there is danger of a newline beging ignored.
- if len(n.Child) > 0 && n.Child[0].Type == TextNode && strings.HasPrefix(n.Child[0].Data, "\n") {
+ if c := n.FirstChild; c != nil && c.Type == TextNode && strings.HasPrefix(c.Data, "\n") {
switch n.Data {
case "pre", "listing", "textarea":
if err := w.WriteByte('\n'); err != nil {
@@ -194,12 +194,15 @@ func render1(w writer, n *Node) error {
// Render any child nodes.
switch n.Data {
case "iframe", "noembed", "noframes", "noscript", "plaintext", "script", "style", "xmp":
- for _, c := range n.Child {
- if c.Type != TextNode {
- return fmt.Errorf("html: raw text element <%s> has non-text child node", n.Data)
- }
- if _, err := w.WriteString(c.Data); err != nil {
- return err
+ for c := n.FirstChild; c != nil; c = c.NextSibling {
+ if c.Type == TextNode {
+ if _, err := w.WriteString(c.Data); err != nil {
+ return err
+ }
+ } else {
+ if err := render1(w, c); err != nil {
+ return err
+ }
}
}
if n.Data == "plaintext" {
@@ -207,17 +210,8 @@ func render1(w writer, n *Node) error {
// last element in the file, with no closing tag.
return plaintextAbort
}
- case "textarea", "title":
- for _, c := range n.Child {
- if c.Type != TextNode {
- return fmt.Errorf("html: RCDATA element <%s> has non-text child node", n.Data)
- }
- if err := render1(w, c); err != nil {
- return err
- }
- }
default:
- for _, c := range n.Child {
+ for c := n.FirstChild; c != nil; c = c.NextSibling {
if err := render1(w, c); err != nil {
return err
}