-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paththead.go
67 lines (50 loc) · 887 Bytes
/
thead.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
61
62
63
64
65
66
67
package hype
import (
"encoding/json"
)
type THead struct {
*Element
}
func (th *THead) MarshalJSON() ([]byte, error) {
if th == nil {
return nil, ErrIsNil("thead")
}
m, err := th.JSONMap()
if err != nil {
return nil, err
}
m["type"] = toType(th)
return json.MarshalIndent(m, "", " ")
}
func (th *THead) String() string {
if th == nil || th.Element == nil {
return ""
}
if th.IsEmptyNode() {
return ""
}
return th.Element.String()
}
func (th *THead) IsEmptyNode() bool {
if th == nil {
return true
}
kids := th.Children()
return len(kids) == 0
}
func NewTHead(el *Element) (*THead, error) {
if el == nil {
return nil, ErrIsNil("thead")
}
th := &THead{
Element: el,
}
return th, nil
}
func NewTHeadNodes(p *Parser, el *Element) (Nodes, error) {
th, err := NewTHead(el)
if err != nil {
return nil, err
}
return Nodes{th}, nil
}