-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
52 lines (39 loc) · 764 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
package md2html
import "fmt"
type Parse interface {
toString() string
parse(string) bool
}
// <Name> Text </Name>
type Node struct {
Name string
Text string
chNodes []Parse
}
func NewNode(name string) *Node {
n := &Node{Name: name}
n.chNodes = make([]Parse, 0)
return n
}
func NewNodeWithText(name, text string) *Node {
n := &Node{Name: name, Text: text}
n.chNodes = make([]Parse, 0)
return n
}
func (n *Node) toString() string {
v := ""
if len(n.chNodes) > 0 {
for _, item := range n.chNodes {
v += item.toString()
}
} else {
v = n.Text
}
return fmt.Sprintf("<%v>%v</%v>\n", n.Name, v, n.Name)
}
func (n *Node) parse(line string) bool {
return false
}
func (n *Node) append(c Parse) {
n.chNodes = append(n.chNodes, c)
}