|
1
|
|
|
from unittest import TestCase |
|
2
|
|
|
|
|
3
|
|
|
from panflute import convert_text, Para, Image, Figure |
|
4
|
|
|
|
|
5
|
|
|
import pandoc_glfm |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class AlertsTest(TestCase): |
|
9
|
|
|
@classmethod |
|
10
|
|
|
def conversion(cls, markdown, fmt="markdown"): |
|
11
|
|
|
doc = convert_text(markdown, standalone=True) |
|
12
|
|
|
doc.format = fmt |
|
13
|
|
|
pandoc_glfm.main(doc) |
|
14
|
|
|
return doc |
|
15
|
|
|
|
|
16
|
|
|
def test_blockquote_empty(self): |
|
17
|
|
|
doc = AlertsTest.conversion( |
|
18
|
|
|
""" |
|
19
|
|
|
> [!note] |
|
20
|
|
|
""", |
|
21
|
|
|
) |
|
22
|
|
|
text = convert_text( |
|
23
|
|
|
doc, |
|
24
|
|
|
input_format="panflute", |
|
25
|
|
|
output_format="markdown", |
|
26
|
|
|
) |
|
27
|
|
|
self.assertEqual( |
|
28
|
|
|
text, |
|
29
|
|
|
""" |
|
30
|
|
|
:::: note |
|
31
|
|
|
::: title |
|
32
|
|
|
Note |
|
33
|
|
|
::: |
|
34
|
|
|
:::: |
|
35
|
|
|
""".strip() |
|
36
|
|
|
) |
|
37
|
|
|
|
|
38
|
|
|
def test_blockquote_rest(self): |
|
39
|
|
|
doc = AlertsTest.conversion( |
|
40
|
|
|
""" |
|
41
|
|
|
> [!note] |
|
42
|
|
|
> **rest** |
|
43
|
|
|
""", |
|
44
|
|
|
) |
|
45
|
|
|
text = convert_text( |
|
46
|
|
|
doc, |
|
47
|
|
|
input_format="panflute", |
|
48
|
|
|
output_format="markdown", |
|
49
|
|
|
) |
|
50
|
|
|
self.assertEqual( |
|
51
|
|
|
text, |
|
52
|
|
|
""" |
|
53
|
|
|
:::: note |
|
54
|
|
|
::: title |
|
55
|
|
|
Note |
|
56
|
|
|
::: |
|
57
|
|
|
|
|
58
|
|
|
**rest** |
|
59
|
|
|
:::: |
|
60
|
|
|
""".strip() |
|
61
|
|
|
) |
|
62
|
|
|
|
|
63
|
|
|
def test_blockquote_newline(self): |
|
64
|
|
|
doc = AlertsTest.conversion( |
|
65
|
|
|
""" |
|
66
|
|
|
> [!note] |
|
67
|
|
|
> |
|
68
|
|
|
> **rest** |
|
69
|
|
|
""", |
|
70
|
|
|
) |
|
71
|
|
|
text = convert_text( |
|
72
|
|
|
doc, |
|
73
|
|
|
input_format="panflute", |
|
74
|
|
|
output_format="markdown", |
|
75
|
|
|
) |
|
76
|
|
|
self.assertEqual( |
|
77
|
|
|
text, |
|
78
|
|
|
""" |
|
79
|
|
|
:::: note |
|
80
|
|
|
::: title |
|
81
|
|
|
Note |
|
82
|
|
|
::: |
|
83
|
|
|
|
|
84
|
|
|
**rest** |
|
85
|
|
|
:::: |
|
86
|
|
|
""".strip() |
|
87
|
|
|
) |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
def test_blockquote_empty_title(self): |
|
91
|
|
|
doc = AlertsTest.conversion( |
|
92
|
|
|
""" |
|
93
|
|
|
> [!note] My title |
|
94
|
|
|
""", |
|
95
|
|
|
) |
|
96
|
|
|
text = convert_text( |
|
97
|
|
|
doc, |
|
98
|
|
|
input_format="panflute", |
|
99
|
|
|
output_format="markdown", |
|
100
|
|
|
) |
|
101
|
|
|
self.assertEqual( |
|
102
|
|
|
text, |
|
103
|
|
|
""" |
|
104
|
|
|
:::: note |
|
105
|
|
|
::: title |
|
106
|
|
|
My title |
|
107
|
|
|
::: |
|
108
|
|
|
:::: |
|
109
|
|
|
""".strip() |
|
110
|
|
|
) |
|
111
|
|
|
|
|
112
|
|
|
def test_blockquote_rest_title(self): |
|
113
|
|
|
doc = AlertsTest.conversion( |
|
114
|
|
|
""" |
|
115
|
|
|
> [!note] My title |
|
116
|
|
|
> **rest** |
|
117
|
|
|
""", |
|
118
|
|
|
) |
|
119
|
|
|
text = convert_text( |
|
120
|
|
|
doc, |
|
121
|
|
|
input_format="panflute", |
|
122
|
|
|
output_format="markdown", |
|
123
|
|
|
) |
|
124
|
|
|
self.assertEqual( |
|
125
|
|
|
text, |
|
126
|
|
|
""" |
|
127
|
|
|
:::: note |
|
128
|
|
|
::: title |
|
129
|
|
|
My title |
|
130
|
|
|
::: |
|
131
|
|
|
|
|
132
|
|
|
**rest** |
|
133
|
|
|
:::: |
|
134
|
|
|
""".strip() |
|
135
|
|
|
) |
|
136
|
|
|
|
|
137
|
|
|
def test_blockquote_newline_title(self): |
|
138
|
|
|
doc = AlertsTest.conversion( |
|
139
|
|
|
""" |
|
140
|
|
|
> [!note] My title |
|
141
|
|
|
> |
|
142
|
|
|
> **rest** |
|
143
|
|
|
""", |
|
144
|
|
|
) |
|
145
|
|
|
text = convert_text( |
|
146
|
|
|
doc, |
|
147
|
|
|
input_format="panflute", |
|
148
|
|
|
output_format="markdown", |
|
149
|
|
|
) |
|
150
|
|
|
self.assertEqual( |
|
151
|
|
|
text, |
|
152
|
|
|
""" |
|
153
|
|
|
:::: note |
|
154
|
|
|
::: title |
|
155
|
|
|
My title |
|
156
|
|
|
::: |
|
157
|
|
|
|
|
158
|
|
|
**rest** |
|
159
|
|
|
:::: |
|
160
|
|
|
""".strip() |
|
161
|
|
|
) |
|
162
|
|
|
|
|
163
|
|
|
def test_blockquote_bullet(self): |
|
164
|
|
|
doc = AlertsTest.conversion( |
|
165
|
|
|
""" |
|
166
|
|
|
> [!note] My title |
|
167
|
|
|
> * **a** |
|
168
|
|
|
> * b |
|
169
|
|
|
> |
|
170
|
|
|
> * c |
|
171
|
|
|
""", |
|
172
|
|
|
) |
|
173
|
|
|
text = convert_text( |
|
174
|
|
|
doc, |
|
175
|
|
|
input_format="panflute", |
|
176
|
|
|
output_format="markdown", |
|
177
|
|
|
) |
|
178
|
|
|
self.assertEqual( |
|
179
|
|
|
text, |
|
180
|
|
|
""" |
|
181
|
|
|
:::: note |
|
182
|
|
|
::: title |
|
183
|
|
|
My title |
|
184
|
|
|
::: |
|
185
|
|
|
|
|
186
|
|
|
- **a** |
|
187
|
|
|
- b |
|
188
|
|
|
- c |
|
189
|
|
|
:::: |
|
190
|
|
|
""".strip() |
|
191
|
|
|
) |
|
192
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
class TakssTest(TestCase): |
|
195
|
|
|
@classmethod |
|
196
|
|
|
def conversion(cls, markdown, fmt="markdown"): |
|
197
|
|
|
doc = convert_text(markdown, standalone=True) |
|
198
|
|
|
doc.format = fmt |
|
199
|
|
|
pandoc_glfm.main(doc) |
|
200
|
|
|
return doc |
|
201
|
|
|
|
|
202
|
|
|
def test_tasks_simple(self): |
|
203
|
|
|
doc = AlertsTest.conversion( |
|
204
|
|
|
""" |
|
205
|
|
|
* [ ] Task 1 |
|
206
|
|
|
* [x] Task 2 |
|
207
|
|
|
* [~] Task 3 |
|
208
|
|
|
|
|
209
|
|
|
""", |
|
210
|
|
|
) |
|
211
|
|
|
text = convert_text( |
|
212
|
|
|
doc, |
|
213
|
|
|
input_format="panflute", |
|
214
|
|
|
output_format="markdown", |
|
215
|
|
|
) |
|
216
|
|
|
self.assertEqual( |
|
217
|
|
|
text, |
|
218
|
|
|
""" |
|
219
|
|
|
- [ ] Task 1 |
|
220
|
|
|
- [x] Task 2 |
|
221
|
|
|
- [ ] ~~Task 3~~ |
|
222
|
|
|
""".strip() |
|
223
|
|
|
) |
|
224
|
|
|
|
|
225
|
|
|
def test_tasks_softbreak(self): |
|
226
|
|
|
doc = AlertsTest.conversion( |
|
227
|
|
|
""" |
|
228
|
|
|
* [ ] Task 1 |
|
229
|
|
|
* [x] Task 2 |
|
230
|
|
|
* [~] Task 3 |
|
231
|
|
|
rest |
|
232
|
|
|
""", |
|
233
|
|
|
) |
|
234
|
|
|
text = convert_text( |
|
235
|
|
|
doc, |
|
236
|
|
|
input_format="panflute", |
|
237
|
|
|
output_format="markdown", |
|
238
|
|
|
) |
|
239
|
|
|
self.assertEqual( |
|
240
|
|
|
text, |
|
241
|
|
|
""" |
|
242
|
|
|
- [ ] Task 1 |
|
243
|
|
|
- [x] Task 2 |
|
244
|
|
|
- [ ] ~~Task 3 rest~~ |
|
245
|
|
|
""".strip() |
|
246
|
|
|
) |
|
247
|
|
|
|
|
248
|
|
|
def test_tasks_linebreak(self): |
|
249
|
|
|
doc = AlertsTest.conversion( |
|
250
|
|
|
""" |
|
251
|
|
|
* [ ] Task 1 |
|
252
|
|
|
* [x] Task 2 |
|
253
|
|
|
* [~] Task 3 |
|
254
|
|
|
|
|
255
|
|
|
rest |
|
256
|
|
|
""", |
|
257
|
|
|
) |
|
258
|
|
|
text = convert_text( |
|
259
|
|
|
doc, |
|
260
|
|
|
input_format="panflute", |
|
261
|
|
|
output_format="markdown", |
|
262
|
|
|
) |
|
263
|
|
|
self.assertEqual( |
|
264
|
|
|
text, |
|
265
|
|
|
""" |
|
266
|
|
|
- [ ] Task 1 |
|
267
|
|
|
|
|
268
|
|
|
- [x] Task 2 |
|
269
|
|
|
|
|
270
|
|
|
- [ ] ~~Task 3~~ |
|
271
|
|
|
|
|
272
|
|
|
~~rest~~ |
|
273
|
|
|
""".strip() |
|
274
|
|
|
) |
|
275
|
|
|
|
|
276
|
|
|
def test_tasks_strikeout(self): |
|
277
|
|
|
doc = AlertsTest.conversion( |
|
278
|
|
|
""" |
|
279
|
|
|
* [ ] Task 1 |
|
280
|
|
|
* [x] Task 2 |
|
281
|
|
|
* [~] ~~Task 3~~ |
|
282
|
|
|
""", |
|
283
|
|
|
) |
|
284
|
|
|
text = convert_text( |
|
285
|
|
|
doc, |
|
286
|
|
|
input_format="panflute", |
|
287
|
|
|
output_format="markdown", |
|
288
|
|
|
) |
|
289
|
|
|
self.assertEqual( |
|
290
|
|
|
text, |
|
291
|
|
|
""" |
|
292
|
|
|
- [ ] Task 1 |
|
293
|
|
|
- [x] Task 2 |
|
294
|
|
|
- [ ] ~~Task 3~~ |
|
295
|
|
|
""".strip() |
|
296
|
|
|
) |
|
297
|
|
|
|