forked from rainycape/gondola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
60 lines (52 loc) · 832 Bytes
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package html
import (
"bytes"
"html/template"
)
type Node struct {
Type Type
Tag string
Attrs Attrs
Content string
Next *Node
Children *Node
Open bool
}
func (n *Node) NChildren() int {
ii := 0
for c := n.Children; c != nil; c = c.Next {
ii++
}
return ii
}
func (n *Node) AppendChild(c *Node) {
last := n.LastChild()
if last != nil {
last.Next = c
} else {
n.Children = c
}
}
func (n *Node) LastChild() *Node {
c := n.Children
if c != nil {
for {
if c.Next == nil {
return c
}
c = c.Next
}
}
return nil
}
func (n *Node) Render(buf *bytes.Buffer) {
n.writeToStringWriter(buf)
}
func (n *Node) String() string {
var buf bytes.Buffer
n.writeToStringWriter(&buf)
return buf.String()
}
func (n *Node) HTML() template.HTML {
return template.HTML(n.String())
}