-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
li.go
67 lines (50 loc) · 858 Bytes
/
li.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 (
"bytes"
"encoding/json"
)
type LI struct {
*Element
Type string
}
func (li *LI) MarshalJSON() ([]byte, error) {
if li == nil {
return nil, ErrIsNil("li")
}
m, err := li.JSONMap()
if err != nil {
return nil, err
}
m["type"] = toType(li)
if li.Type != "" {
m["list-type"] = li.Type
}
return json.MarshalIndent(m, "", " ")
}
func (li *LI) MD() string {
if li == nil {
return ""
}
bb := &bytes.Buffer{}
switch li.Type {
case "ol":
bb.WriteString("1. ")
default:
bb.WriteString("* ")
}
bb.WriteString(li.Children().MD())
return bb.String()
}
func NewLINodes(p *Parser, el *Element) (Nodes, error) {
if el == nil {
return nil, nil
}
li := &LI{
Element: el,
Type: "ul",
}
if par, ok := el.Parent.(AtomableNode); ok {
li.Type = par.Atom().String()
}
return Nodes{li}, nil
}