-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom.go
39 lines (34 loc) · 873 Bytes
/
dom.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
package mobiledoc
type node struct {
parent, firstChild, lastChild, prevSibling, nextSibling *node
tagname, value string
attributes map[string]string
}
func newNode(tagname, value string) *node {
return &node{
tagname: tagname,
value: value,
attributes: make(map[string]string),
}
}
// appendChild adds a node c as a child of n.
//
// It will panic if c already has a parent or siblings.
func (n *node) appendChild(c *node) {
if c.parent != nil || c.prevSibling != nil || c.nextSibling != nil {
panic("node: appendChild called for an attached child Node")
}
last := n.lastChild
if last != nil {
last.nextSibling = c
} else {
n.firstChild = c
}
n.lastChild = c
c.parent = n
c.prevSibling = last
}
// addAttribute adds an attribute key with value value.
func (n *node) addAttribute(key, value string) {
n.attributes[key] = value
}