-
Notifications
You must be signed in to change notification settings - Fork 13
/
markup.go
97 lines (77 loc) · 2.01 KB
/
markup.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package plugin
import (
"strings"
"github.com/vito/booklit"
)
func (plugin *Plugin) T(content booklit.Content) booklit.Content {
return &booklit.Reference{
TagName: "term-" + plugin.plural.Singular(strings.ToLower(strings.ReplaceAll(content.String(), "'", ""))),
Content: content,
}
}
func (plugin *Plugin) B(content booklit.Content) booklit.Content {
return &booklit.Reference{
TagName: "binding-" + content.String(),
}
}
func (plug *Plugin) Term(term, definition booklit.Content, literate ...booklit.Content) error {
body := append([]booklit.Content{definition}, literate...)
prose, err := plug.BassLiterate(body...)
if err != nil {
return err
}
section := &booklit.Section{
Style: "bass-term",
Parent: plug.Section,
Title: booklit.Styled{
Style: "term",
Content: term,
},
Body: prose,
Processor: plug.Section.Processor,
Location: plug.Section.InvokeLocation,
TitleLocation: plug.Section.InvokeLocation,
}
tag := booklit.Tag{
Name: "term-" + term.String(),
Title: section.Title,
Section: section,
Content: definition,
Location: plug.Section.InvokeLocation,
}
section.PrimaryTag = tag
section.Tags = []booklit.Tag{tag}
plug.Section.Children = append(plug.Section.Children, section)
return nil
}
func (*Plugin) SideBySide(content ...booklit.Content) booklit.Content {
return booklit.Styled{
Style: "side-by-side",
Content: booklit.Sequence(content),
}
}
func (*Plugin) Construction(content booklit.Content) booklit.Content {
return booklit.Styled{
Style: "construction",
Content: content,
}
}
func (plug *Plugin) Commands(commandBlock booklit.Content) (booklit.Content, error) {
var cmds booklit.Sequence
lines := strings.Split(commandBlock.String(), "\n")
for _, line := range lines {
if len(line) == 0 {
continue
}
cmd, err := plug.Syntax("sh", booklit.String(line))
if err != nil {
return nil, err
}
cmds = append(cmds, cmd)
}
return booklit.Styled{
Style: "sh-commands",
Block: true,
Content: cmds,
}, nil
}