-
Notifications
You must be signed in to change notification settings - Fork 1
/
figure_test.go
195 lines (178 loc) · 4.73 KB
/
figure_test.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
// Copyright 2023 The goldmark-figure authors
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
package figure_test
import (
"testing"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/testutil"
figure "github.com/mangoumbrella/goldmark-figure"
)
func TestFigure(t *testing.T) {
markdown := goldmark.New(
goldmark.WithExtensions(
figure.Figure,
),
)
count := 0
count++
testutil.DoTestCase(markdown, testutil.MarkdownTestCase{
No: count,
Description: "Link not image",
Markdown: `
[Just a link](https://example.com)
This is the paragraph content
`,
Expected: `
<p><a href="https://example.com">Just a link</a>
This is the paragraph content</p>
`,
}, t)
count++
testutil.DoTestCase(markdown, testutil.MarkdownTestCase{
No: count,
Description: "Simple",
Markdown: `
![Alt text](https://example.com/image.jpg)
This is the paragraph content.
This is the continued line.
`,
Expected: `<figure>
<img src="https://example.com/image.jpg" alt="Alt text">
<figcaption><p>This is the paragraph content.
This is the continued line.</p></figcaption>
</figure>
`,
}, t)
count++
testutil.DoTestCase(markdown, testutil.MarkdownTestCase{
No: count,
Description: "With title",
Markdown: `
![Alt text](https://example.com/image.jpg "Image title")
This is the paragraph content.
This is the continued line.
`,
Expected: `<figure>
<img src="https://example.com/image.jpg" alt="Alt text" title="Image title">
<figcaption><p>This is the paragraph content.
This is the continued line.</p></figcaption>
</figure>
`,
}, t)
count++
testutil.DoTestCase(markdown, testutil.MarkdownTestCase{
No: count,
Description: "Image in the middle isn't a figure",
Markdown: `
Following image is in the middle:
![Alt text](https://example.com/image.jpg)
So this won't be a figure.
`,
Expected: `
<p>Following image is in the middle:
<img src="https://example.com/image.jpg" alt="Alt text">
So this won't be a figure.</p>
`,
}, t)
count++
testutil.DoTestCase(markdown, testutil.MarkdownTestCase{
No: count,
Description: "Multiple paragraph content",
Markdown: `
First paragraph.
![Alt text](https://example.com/image.jpg)
This is the paragraph content.
This is the continued line with **bold**.
Last paragraph.
`,
Expected: `<p>First paragraph.</p>
<figure>
<img src="https://example.com/image.jpg" alt="Alt text">
<figcaption><p>This is the paragraph content.
This is the continued line with <strong>bold</strong>.</p></figcaption>
</figure>
<p>Last paragraph.</p>
`,
}, t)
count++
testutil.DoTestCase(markdown, testutil.MarkdownTestCase{
No: count,
Description: "Two images",
Markdown: `
![Picture of Oscar.](/path/to/cat1.jpg)
![Picture of Luna.](/path/to/cat2.jpg)
Awesome captions about the **kitties**.
`,
Expected: `<figure>
<img src="/path/to/cat1.jpg" alt="Picture of Oscar.">
<img src="/path/to/cat2.jpg" alt="Picture of Luna.">
<figcaption><p>Awesome captions about the <strong>kitties</strong>.</p></figcaption>
</figure>
`,
}, t)
count++
testutil.DoTestCase(markdown, testutil.MarkdownTestCase{
No: count,
Description: "Three images",
Markdown: `
![Picture of Oscar.](/path/to/cat1.jpg)
![Picture of Luna.](/path/to/cat2.jpg)
![Picture of Oreo.](/path/to/cat3.jpg)
Awesome captions about the **kitties**.
`,
Expected: `<figure>
<img src="/path/to/cat1.jpg" alt="Picture of Oscar.">
<img src="/path/to/cat2.jpg" alt="Picture of Luna.">
<img src="/path/to/cat3.jpg" alt="Picture of Oreo.">
<figcaption><p>Awesome captions about the <strong>kitties</strong>.</p></figcaption>
</figure>
`,
}, t)
}
func TestFigureWithImageLink(t *testing.T) {
markdown := goldmark.New(
goldmark.WithExtensions(
figure.Figure.WithImageLink(),
),
)
count := 0
count++
testutil.DoTestCase(markdown, testutil.MarkdownTestCase{
No: count,
Description: "Simple",
Markdown: `
![Alt text](https://example.com/image.jpg)
This is caption.
`,
Expected: `<figure>
<a href="https://example.com/image.jpg">
<img src="https://example.com/image.jpg" alt="Alt text">
</a>
<figcaption><p>This is caption.</p></figcaption>
</figure>
`,
}, t)
count++
testutil.DoTestCase(markdown, testutil.MarkdownTestCase{
No: count,
Description: "Multi images",
Markdown: `
![Picture of Oscar.](/path/to/cat1.jpg)
![Picture of Luna.](/path/to/cat2.jpg)
Awesome captions about the **kitties**.
`,
Expected: `<figure>
<a href="/path/to/cat1.jpg">
<img src="/path/to/cat1.jpg" alt="Picture of Oscar.">
</a>
<a href="/path/to/cat2.jpg">
<img src="/path/to/cat2.jpg" alt="Picture of Luna.">
</a>
<figcaption><p>Awesome captions about the <strong>kitties</strong>.</p></figcaption>
</figure>
`,
}, t)
}