-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
paragraph.go
63 lines (47 loc) · 819 Bytes
/
paragraph.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
package hype
import (
"encoding/json"
)
type Paragraph struct {
*Element
}
func (p *Paragraph) MarshalJSON() ([]byte, error) {
if p == nil {
return nil, ErrIsNil("p")
}
m, err := p.JSONMap()
if err != nil {
return nil, err
}
m["type"] = toType(p)
return json.MarshalIndent(m, "", " ")
}
func (p *Paragraph) IsEmptyNode() bool {
if p == nil {
return true
}
kids := p.Children()
if len(kids) == 0 {
return true
}
return IsEmptyNode(kids)
}
func (p *Paragraph) MD() string {
if p == nil {
return ""
}
return p.Children().MD()
}
func NewParagraphNodes(p *Parser, el *Element) (Nodes, error) {
var nodes Nodes
if el == nil {
return nil, ErrIsNil("el")
}
if IsEmptyNode(el) {
return nodes, nil
}
nodes = append(nodes, &Paragraph{
Element: el,
})
return nodes, nil
}