-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfigcaption.go
62 lines (47 loc) · 894 Bytes
/
figcaption.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
package hype
import (
"encoding/json"
"strings"
)
type Figcaption struct {
*Element
}
func (fc *Figcaption) MarshalJSON() ([]byte, error) {
if fc == nil {
return nil, ErrIsNil("figcaption")
}
fc.RLock()
defer fc.RUnlock()
m, err := fc.JSONMap()
if err != nil {
return nil, err
}
m["type"] = toType(fc)
return json.MarshalIndent(m, "", " ")
}
func (fc *Figcaption) MD() string {
if fc == nil {
return ""
}
bb := &strings.Builder{}
bb.WriteString("> *")
bb.WriteString(fc.Nodes.MD())
bb.WriteString("*")
return bb.String()
}
func NewFigcaption(el *Element) (*Figcaption, error) {
if el == nil {
return nil, el.WrapErr(ErrIsNil("element"))
}
f := &Figcaption{
Element: el,
}
return f, nil
}
func NewFigcaptionNodes(p *Parser, el *Element) (Nodes, error) {
f, err := NewFigcaption(el)
if err != nil {
return nil, err
}
return Nodes{f}, nil
}