-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathlist.go
51 lines (43 loc) · 934 Bytes
/
list.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
package booklit
import (
"fmt"
"strings"
)
// List is a block content containing a list of content, either ordered or
// unordered.
type List struct {
// The items in the list.
Items []Content
// Whether the list is ordered.
Ordered bool
}
// IsFlow returns false.
func (con List) IsFlow() bool {
return false
}
// String summarizes the content for debugging purposes.
func (con List) String() string {
var str string
for i, c := range con.Items {
var text string
for _, line := range strings.Split(strings.TrimRight(c.String(), "\n"), "\n") {
if text == "" {
text = line
} else if line == "" {
text += "\n"
} else {
text += "\n " + line
}
}
if con.Ordered {
str += fmt.Sprintf("%d. %s\n\n", i+1, text)
} else {
str += fmt.Sprintf("* %s\n\n", text)
}
}
return str
}
// Visit calls VisitList.
func (con List) Visit(visitor Visitor) error {
return visitor.VisitList(con)
}