This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
list.go
54 lines (46 loc) · 1.63 KB
/
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
52
53
54
package blocks
import "fmt"
// List is the block representing a set of related elements. It must be the same as all ListItem.Marker.
type List struct {
// Items are the entries of the List. There should be at least one.
Items []ListItem
// Marker is the type of the list. All entries have the same type. See SameAs for information about same types.
Marker ListMarker
}
// ID returns this list's id. It is list- and the list's number.
func (l List) ID(counter *IDCounter) string {
counter.lists++
return fmt.Sprintf("list-%d", counter.lists)
}
// ListItem is an entry in a List.
type ListItem struct {
Marker ListMarker
// Level is equal to amount of asterisks.
// * -> Level = 1
// **. -> Level = 2
Level uint
// Contents are Mycomarkup blocks contained in this list item.
Contents []Block
}
// ID returns an empty string because list items don't have ids.
func (l ListItem) ID(_ *IDCounter) string {
return ""
}
// ListMarker is the type of a ListItem or a List.
type ListMarker int
const (
// MarkerUnordered is for bullets like * (no point).
MarkerUnordered ListMarker = iota
// MarkerOrdered is for bullets like *. (with point).
MarkerOrdered
// MarkerTodoDone is for bullets like *v (with tick).
MarkerTodoDone
// MarkerTodo is for bullets like *x (with cross).
MarkerTodo
)
// SameAs is true if both list markers are of the same type. MarkerTodoDone and MarkerTodo are considered same to each other. All other markers are different from each other.
func (m1 ListMarker) SameAs(m2 ListMarker) bool {
return (m1 == m2) ||
((m1 == MarkerTodoDone) && (m2 == MarkerTodo)) ||
((m1 == MarkerTodo) && (m2 == MarkerTodoDone))
}