/
expr.go
229 lines (183 loc) · 4.23 KB
/
expr.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package markdown
import (
"fmt"
"github.com/yuin/goldmark/ast"
)
type Visitor interface {
VisitDocument(expr Document)
VisitTextBlock(expr TextBlock)
VisitHTMLBlock(expr HTMLBlock)
VisitParagraph(expr Paragraph)
VisitText(expr Text)
VisitString(expr String)
VisitList(expr List)
VisitListItem(expr ListItem)
VisitCodeSpan(expr CodeSpan)
VisitRawHTML(expr RawHTML)
VisitLink(expr Link)
VisitAutoLink(expr AutoLink)
VisitHeading(expr Heading)
VisitEmphasis(expr Emphasis)
}
type Expr interface {
Visit(Visitor)
String() string
}
type Document struct {
node ast.Node
children []Expr
}
func (d Document) Visit(v Visitor) {
v.VisitDocument(d)
}
func (d Document) String() string {
return "Document"
}
type TextBlock struct {
node ast.Node
blanksBefore bool
code bool
language string
lines []string
}
func (t TextBlock) Visit(v Visitor) {
v.VisitTextBlock(t)
}
func (t TextBlock) String() string {
return fmt.Sprintf("TextBlock{blanksBefore: %v, code: %v, language: %q, lines: %d}", t.blanksBefore, t.code, t.language, len(t.lines))
}
type HTMLBlock struct {
node ast.Node
blanksBefore bool
lines []string
}
func (h HTMLBlock) Visit(v Visitor) {
v.VisitHTMLBlock(h)
}
func (h HTMLBlock) String() string {
return fmt.Sprintf("HTMLBlock{blanksBefore: %v, lines: %d}", h.blanksBefore, len(h.lines))
}
type Paragraph struct {
node ast.Node
blanksBefore bool
children []Expr
}
func (p Paragraph) Visit(v Visitor) {
v.VisitParagraph(p)
}
func (p Paragraph) String() string {
return fmt.Sprintf("Paragraph{blanksBefore: %v, children: %d}", p.blanksBefore, len(p.children))
}
type Text struct {
node ast.Node
hardBreak bool
softBreak bool
text string
}
func (t Text) Visit(v Visitor) {
v.VisitText(t)
}
func (t Text) String() string {
return fmt.Sprintf("Text{hardBreak: %v, softBreak: %v, text: %q}", t.hardBreak, t.softBreak, t.text)
}
type String struct {
node ast.Node
text string
}
func (s String) Visit(v Visitor) {
v.VisitString(s)
}
func (s String) String() string {
return fmt.Sprintf("String{text: %q}", s.text)
}
type List struct {
node ast.Node
blanksBefore bool
marker string
tight bool
children []Expr
}
func (l List) Visit(v Visitor) {
v.VisitList(l)
}
func (l List) String() string {
return fmt.Sprintf("List{blanksBefore: %v, marker:%s, tight:%v children: %d}", l.blanksBefore, l.marker, l.tight, len(l.children))
}
type ListItem struct {
node ast.Node
blanksBefore bool
children []Expr
}
func (l ListItem) Visit(v Visitor) {
v.VisitListItem(l)
}
func (l ListItem) String() string {
return fmt.Sprintf("ListItem{blanksBefore: %v, children: %d}", l.blanksBefore, len(l.children))
}
type CodeSpan struct {
node ast.Node
children []Expr
}
func (c CodeSpan) Visit(v Visitor) {
v.VisitCodeSpan(c)
}
func (c CodeSpan) String() string {
return fmt.Sprintf("CodeSpan{children: %d}", len(c.children))
}
type RawHTML struct {
node ast.Node
lines []string
}
func (r RawHTML) Visit(v Visitor) {
v.VisitRawHTML(r)
}
func (r RawHTML) String() string {
return fmt.Sprintf("RawHTML{lines: %d}", len(r.lines))
}
type Link struct {
node ast.Node
destination string
title string
}
func (l Link) Visit(v Visitor) {
v.VisitLink(l)
}
func (l Link) String() string {
return fmt.Sprintf("Link{destination: %v, title: %v}", l.destination, l.title)
}
type AutoLink struct {
node ast.Node
autoLinkType ast.AutoLinkType
protocol string
value string
}
func (a AutoLink) Visit(v Visitor) {
v.VisitAutoLink(a)
}
func (a AutoLink) String() string {
return fmt.Sprintf("Autolink{type: %d, protocol: %s, value: %v}", a.autoLinkType, a.protocol, a.value)
}
type Heading struct {
node ast.Node
text string
children []Expr
blanksBefore bool
level int
}
func (h Heading) Visit(v Visitor) {
v.VisitHeading(h)
}
func (h Heading) String() string {
return fmt.Sprintf("Heading{level: %d, blanksBefore:%v, children:%d}", h.level, h.blanksBefore, len(h.children))
}
type Emphasis struct {
node ast.Node
children []Expr
level int
}
func (e Emphasis) Visit(v Visitor) {
v.VisitEmphasis(e)
}
func (e Emphasis) String() string {
return fmt.Sprintf("Emphasis{}")
}