1
|
|
|
from unittest import TestCase |
2
|
|
|
|
3
|
|
|
import platformdirs |
4
|
|
|
from panflute import convert_text |
5
|
|
|
|
6
|
|
|
import pandoc_latex_tip |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class TipTest(TestCase): |
10
|
|
|
def verify_conversion( |
11
|
|
|
self, |
12
|
|
|
text, |
13
|
|
|
expected, |
14
|
|
|
transform, |
15
|
|
|
input_format="markdown", |
16
|
|
|
output_format="latex", |
17
|
|
|
standalone=False, # noqa: FBT002 |
18
|
|
|
) -> None: |
19
|
|
|
""" |
20
|
|
|
Verify the conversion. |
21
|
|
|
|
22
|
|
|
Parameters |
23
|
|
|
---------- |
24
|
|
|
text |
25
|
|
|
input text |
26
|
|
|
expected |
27
|
|
|
expected text |
28
|
|
|
transform |
29
|
|
|
filter function |
30
|
|
|
input_format |
31
|
|
|
input format |
32
|
|
|
output_format |
33
|
|
|
output format |
34
|
|
|
standalone |
35
|
|
|
is the output format standalone ? |
36
|
|
|
""" |
37
|
|
|
doc = convert_text(text, input_format=input_format, standalone=True) |
38
|
|
|
doc.format = output_format |
39
|
|
|
doc = transform(doc) |
40
|
|
|
converted = convert_text( |
41
|
|
|
doc.content, |
42
|
|
|
input_format="panflute", |
43
|
|
|
output_format=output_format, |
44
|
|
|
extra_args=["--wrap=none"], |
45
|
|
|
standalone=standalone, |
46
|
|
|
) |
47
|
|
|
print("-----------------------------------") |
48
|
|
|
print(converted) |
49
|
|
|
print() |
50
|
|
|
print(expected) |
51
|
|
|
self.assertEqual(converted.strip(), expected.strip()) # noqa: PT009 |
52
|
|
|
|
53
|
|
|
def test_span(self): |
54
|
|
|
self.verify_conversion( |
55
|
|
|
""" |
56
|
|
|
--- |
57
|
|
|
pandoc-latex-tip: |
58
|
|
|
- classes: [tip, listing] |
59
|
|
|
icons: |
60
|
|
|
- {name: fa-file-text, color: darksalmon, link: http://www.google.fr} |
61
|
|
|
- fa-comments |
62
|
|
|
- image: Tux.pdf |
63
|
|
|
size: 2em |
64
|
|
|
position: right |
65
|
|
|
|
66
|
|
|
- classes: [warning] |
67
|
|
|
icons: fa-comments |
68
|
|
|
|
69
|
|
|
- classes: [tip] |
70
|
|
|
position: left |
71
|
|
|
|
72
|
|
|
- classes: [v5.0] |
73
|
|
|
icons: |
74
|
|
|
- name: far-user |
75
|
|
|
color: orange |
76
|
|
|
--- |
77
|
|
|
|
78
|
|
|
[]{.tip .listing}[]{.tip}[]{.warning}[]{.v5.0} |
79
|
|
|
""", |
80
|
|
|
f""" |
81
|
|
|
{{}} |
82
|
|
|
\\checkoddpage%% |
83
|
|
|
\\ifoddpage%% |
84
|
|
|
\\PandocLatexTipOddRight%% |
85
|
|
|
\\else%% |
86
|
|
|
\\PandocLatexTipEvenRight%% |
87
|
|
|
\\fi%% |
88
|
|
|
\\marginnote{{\\href{{http://www.google.fr}}{{\\includegraphics[width=\\linewidth,height=2em,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/darksalmon/fa-file-text.png}}}}\\includegraphics[width=\\linewidth,height=2em,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/black/fa-comments.png}}\\includegraphics[width=\\linewidth,height=2em,keepaspectratio]{{Tux.pdf}}}}[0pt]\\vspace{{0cm}}%% |
89
|
|
|
{{}} |
90
|
|
|
\\checkoddpage%% |
91
|
|
|
\\ifoddpage%% |
92
|
|
|
\\PandocLatexTipOddLeft%% |
93
|
|
|
\\else%% |
94
|
|
|
\\PandocLatexTipEvenLeft%% |
95
|
|
|
\\fi%% |
96
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.25in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/black/fa-exclamation-circle.png}}}}[0pt]\\vspace{{0cm}}%% |
97
|
|
|
{{}} |
98
|
|
|
\\checkoddpage%% |
99
|
|
|
\\ifoddpage%% |
100
|
|
|
\\PandocLatexTipOddLeft%% |
101
|
|
|
\\else%% |
102
|
|
|
\\PandocLatexTipEvenLeft%% |
103
|
|
|
\\fi%% |
104
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.25in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/black/fa-comments.png}}}}[0pt]\\vspace{{0cm}}%% |
105
|
|
|
{{}} |
106
|
|
|
\\checkoddpage%% |
107
|
|
|
\\ifoddpage%% |
108
|
|
|
\\PandocLatexTipOddLeft%% |
109
|
|
|
\\else%% |
110
|
|
|
\\PandocLatexTipEvenLeft%% |
111
|
|
|
\\fi%% |
112
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.25in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/orange/far-user.png}}}}[0pt]\\vspace{{0cm}}%% |
113
|
|
|
""", |
114
|
|
|
pandoc_latex_tip.main, |
115
|
|
|
) |
116
|
|
|
|
117
|
|
|
def test_codeblock(self): |
118
|
|
|
self.verify_conversion( |
119
|
|
|
""" |
120
|
|
|
--- |
121
|
|
|
pandoc-latex-tip: |
122
|
|
|
- classes: [tip, listing] |
123
|
|
|
icons: |
124
|
|
|
- {name: fa-file-text, color: darksalmon, link: http://www.google.fr} |
125
|
|
|
- fa-comments |
126
|
|
|
size: 36 |
127
|
|
|
position: right |
128
|
|
|
|
129
|
|
|
- classes: [warning] |
130
|
|
|
icons: fa-comments |
131
|
|
|
|
132
|
|
|
- classes: [tip] |
133
|
|
|
position: left |
134
|
|
|
|
135
|
|
|
- classes: [v5.0] |
136
|
|
|
icons: |
137
|
|
|
- name: far-user |
138
|
|
|
color: orange |
139
|
|
|
--- |
140
|
|
|
|
141
|
|
|
~~~{.python .warning} |
142
|
|
|
main() |
143
|
|
|
~~~ |
144
|
|
|
|
145
|
|
|
""", |
146
|
|
|
f""" |
147
|
|
|
\\checkoddpage%% |
148
|
|
|
\\ifoddpage%% |
149
|
|
|
\\PandocLatexTipOddLeft%% |
150
|
|
|
\\else%% |
151
|
|
|
\\PandocLatexTipEvenLeft%% |
152
|
|
|
\\fi%% |
153
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.25in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/black/fa-comments.png}}}}[0pt]\\vspace{{0cm}}%% |
154
|
|
|
|
155
|
|
|
\\begin{{Shaded}} |
156
|
|
|
\\begin{{Highlighting}}[] |
157
|
|
|
\\NormalTok{{main()}} |
158
|
|
|
\\end{{Highlighting}} |
159
|
|
|
\\end{{Shaded}} |
160
|
|
|
|
161
|
|
|
""", |
162
|
|
|
pandoc_latex_tip.main, |
163
|
|
|
) |
164
|
|
|
|
165
|
|
|
def test_div(self): |
166
|
|
|
self.verify_conversion( |
167
|
|
|
""" |
168
|
|
|
--- |
169
|
|
|
pandoc-latex-tip: |
170
|
|
|
- classes: [tip, listing] |
171
|
|
|
icons: |
172
|
|
|
- {name: fa-file-text, color: darksalmon, link: http://www.google.fr} |
173
|
|
|
- fa-comments |
174
|
|
|
size: 36 |
175
|
|
|
position: right |
176
|
|
|
|
177
|
|
|
- classes: [warning] |
178
|
|
|
icons: fa-comments |
179
|
|
|
|
180
|
|
|
- classes: [tip] |
181
|
|
|
position: left |
182
|
|
|
|
183
|
|
|
- classes: [v5.0] |
184
|
|
|
icons: |
185
|
|
|
- name: far-user |
186
|
|
|
color: orange |
187
|
|
|
--- |
188
|
|
|
|
189
|
|
|
::: warning |
190
|
|
|
Division |
191
|
|
|
::: |
192
|
|
|
""", |
193
|
|
|
f""" |
194
|
|
|
Division |
195
|
|
|
\\checkoddpage%% |
196
|
|
|
\\ifoddpage%% |
197
|
|
|
\\PandocLatexTipOddLeft%% |
198
|
|
|
\\else%% |
199
|
|
|
\\PandocLatexTipEvenLeft%% |
200
|
|
|
\\fi%% |
201
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.25in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/black/fa-comments.png}}}}[0pt]\\vspace{{0cm}}%% |
202
|
|
|
""", |
203
|
|
|
pandoc_latex_tip.main, |
204
|
|
|
) |
205
|
|
|
self.verify_conversion( |
206
|
|
|
""" |
207
|
|
|
::: { |
208
|
|
|
latex-tip-icon=fa-address-book |
209
|
|
|
latex-tip-size=24 |
210
|
|
|
latex-tip-position=right |
211
|
|
|
latex-tip-color=lightskyblue} ::: |
212
|
|
|
Division |
213
|
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
214
|
|
|
""", |
215
|
|
|
f""" |
216
|
|
|
Division |
217
|
|
|
\\checkoddpage%% |
218
|
|
|
\\ifoddpage%% |
219
|
|
|
\\PandocLatexTipOddRight%% |
220
|
|
|
\\else%% |
221
|
|
|
\\PandocLatexTipEvenRight%% |
222
|
|
|
\\fi%% |
223
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.33333in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/lightskyblue/fa-address-book.png}}}}[0pt]\\vspace{{0cm}}%% |
224
|
|
|
""", |
225
|
|
|
pandoc_latex_tip.main, |
226
|
|
|
) |
227
|
|
|
self.verify_conversion( |
228
|
|
|
""" |
229
|
|
|
::: { |
230
|
|
|
latex-tip-image=Tux.pdf |
231
|
|
|
latex-tip-size=24 |
232
|
|
|
latex-tip-position=right} ::: |
233
|
|
|
Division |
234
|
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
235
|
|
|
""", |
236
|
|
|
f""" |
237
|
|
|
Division |
238
|
|
|
\\checkoddpage%% |
239
|
|
|
\\ifoddpage%% |
240
|
|
|
\\PandocLatexTipOddRight%% |
241
|
|
|
\\else%% |
242
|
|
|
\\PandocLatexTipEvenRight%% |
243
|
|
|
\\fi%% |
244
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.33333in,keepaspectratio]{{Tux.pdf}}}}[0pt]\\vspace{{0cm}}%% |
245
|
|
|
""", |
246
|
|
|
pandoc_latex_tip.main, |
247
|
|
|
) |
248
|
|
|
|
249
|
|
|
def test_div_div(self): |
250
|
|
|
self.verify_conversion( |
251
|
|
|
""" |
252
|
|
|
--- |
253
|
|
|
pandoc-latex-tip: |
254
|
|
|
- classes: [tip, listing] |
255
|
|
|
icons: |
256
|
|
|
- {name: fa-file-text, color: darksalmon, link: http://www.google.fr} |
257
|
|
|
- fa-comments |
258
|
|
|
size: 36 |
259
|
|
|
position: right |
260
|
|
|
|
261
|
|
|
- classes: [warning] |
262
|
|
|
icons: fa-comments |
263
|
|
|
|
264
|
|
|
- classes: [tip] |
265
|
|
|
position: left |
266
|
|
|
|
267
|
|
|
- classes: [v5.0] |
268
|
|
|
icons: |
269
|
|
|
- name: far-user |
270
|
|
|
color: orange |
271
|
|
|
--- |
272
|
|
|
|
273
|
|
|
::: warning |
274
|
|
|
::: div |
275
|
|
|
Division |
276
|
|
|
::: |
277
|
|
|
::: |
278
|
|
|
""", |
279
|
|
|
f""" |
280
|
|
|
Division |
281
|
|
|
\\checkoddpage%% |
282
|
|
|
\\ifoddpage%% |
283
|
|
|
\\PandocLatexTipOddLeft%% |
284
|
|
|
\\else%% |
285
|
|
|
\\PandocLatexTipEvenLeft%% |
286
|
|
|
\\fi%% |
287
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.25in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/black/fa-comments.png}}}}[0pt]\\vspace{{0cm}}%% |
288
|
|
|
""", |
289
|
|
|
pandoc_latex_tip.main, |
290
|
|
|
) |
291
|
|
|
|
292
|
|
|
def test_div_rule(self): |
293
|
|
|
self.verify_conversion( |
294
|
|
|
""" |
295
|
|
|
--- |
296
|
|
|
pandoc-latex-tip: |
297
|
|
|
- classes: [tip, listing] |
298
|
|
|
icons: |
299
|
|
|
- {name: fa-file-text, color: darksalmon, link: http://www.google.fr} |
300
|
|
|
- fa-comments |
301
|
|
|
size: 36 |
302
|
|
|
position: right |
303
|
|
|
|
304
|
|
|
- classes: [warning] |
305
|
|
|
icons: fa-comments |
306
|
|
|
|
307
|
|
|
- classes: [tip] |
308
|
|
|
position: left |
309
|
|
|
|
310
|
|
|
- classes: [v5.0] |
311
|
|
|
icons: |
312
|
|
|
- name: far-user |
313
|
|
|
color: orange |
314
|
|
|
--- |
315
|
|
|
|
316
|
|
|
::: warning |
317
|
|
|
----------- |
318
|
|
|
::: |
319
|
|
|
""", |
320
|
|
|
f""" |
321
|
|
|
\\checkoddpage%% |
322
|
|
|
\\ifoddpage%% |
323
|
|
|
\\PandocLatexTipOddLeft%% |
324
|
|
|
\\else%% |
325
|
|
|
\\PandocLatexTipEvenLeft%% |
326
|
|
|
\\fi%% |
327
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.25in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/black/fa-comments.png}}}}[0pt]\\vspace{{0cm}}%% |
328
|
|
|
|
329
|
|
|
\\begin{{center}}\\rule{{0.5\\linewidth}}{{0.5pt}}\\end{{center}} |
330
|
|
|
""", |
331
|
|
|
pandoc_latex_tip.main, |
332
|
|
|
) |
333
|
|
|
|
334
|
|
|
def test_div_lineblock(self): |
335
|
|
|
self.verify_conversion( |
336
|
|
|
""" |
337
|
|
|
--- |
338
|
|
|
pandoc-latex-tip: |
339
|
|
|
- classes: [tip, listing] |
340
|
|
|
icons: |
341
|
|
|
- {name: fa-file-text, color: darksalmon, link: http://www.google.fr} |
342
|
|
|
- fa-comments |
343
|
|
|
size: 36 |
344
|
|
|
position: right |
345
|
|
|
|
346
|
|
|
- classes: [warning] |
347
|
|
|
icons: fa-comments |
348
|
|
|
|
349
|
|
|
- classes: [tip] |
350
|
|
|
position: left |
351
|
|
|
|
352
|
|
|
- classes: [v5.0] |
353
|
|
|
icons: |
354
|
|
|
- name: far-user |
355
|
|
|
color: orange |
356
|
|
|
--- |
357
|
|
|
|
358
|
|
|
::: warning |
359
|
|
|
| Lineblock |
360
|
|
|
| continue |
361
|
|
|
::: |
362
|
|
|
""", |
363
|
|
|
f""" |
364
|
|
|
Lineblock |
365
|
|
|
\\checkoddpage%% |
366
|
|
|
\\ifoddpage%% |
367
|
|
|
\\PandocLatexTipOddLeft%% |
368
|
|
|
\\else%% |
369
|
|
|
\\PandocLatexTipEvenLeft%% |
370
|
|
|
\\fi%% |
371
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.25in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/black/fa-comments.png}}}}[0pt]\\vspace{{0cm}}%% |
372
|
|
|
\\\\ |
373
|
|
|
continue |
374
|
|
|
""", |
375
|
|
|
pandoc_latex_tip.main, |
376
|
|
|
) |
377
|
|
|
|
378
|
|
|
def test_div_codeblock(self): |
379
|
|
|
self.verify_conversion( |
380
|
|
|
""" |
381
|
|
|
--- |
382
|
|
|
pandoc-latex-tip: |
383
|
|
|
- classes: [tip, listing] |
384
|
|
|
icons: |
385
|
|
|
- {name: fa-file-text, color: darksalmon, link: http://www.google.fr} |
386
|
|
|
- fa-comments |
387
|
|
|
size: 36 |
388
|
|
|
position: right |
389
|
|
|
|
390
|
|
|
- classes: [warning] |
391
|
|
|
icons: fa-comments |
392
|
|
|
|
393
|
|
|
- classes: [tip] |
394
|
|
|
position: left |
395
|
|
|
|
396
|
|
|
- classes: [v5.0] |
397
|
|
|
icons: |
398
|
|
|
- name: far-user |
399
|
|
|
color: orange |
400
|
|
|
--- |
401
|
|
|
|
402
|
|
|
::: warning |
403
|
|
|
~~~python |
404
|
|
|
main() |
405
|
|
|
~~~ |
406
|
|
|
::: |
407
|
|
|
""", |
408
|
|
|
f""" |
409
|
|
|
\\checkoddpage%% |
410
|
|
|
\\ifoddpage%% |
411
|
|
|
\\PandocLatexTipOddLeft%% |
412
|
|
|
\\else%% |
413
|
|
|
\\PandocLatexTipEvenLeft%% |
414
|
|
|
\\fi%% |
415
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.25in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/black/fa-comments.png}}}}[0pt]\\vspace{{0cm}}%% |
416
|
|
|
|
417
|
|
|
\\begin{{Shaded}} |
418
|
|
|
\\begin{{Highlighting}}[] |
419
|
|
|
\\NormalTok{{main()}} |
420
|
|
|
\\end{{Highlighting}} |
421
|
|
|
\\end{{Shaded}} |
422
|
|
|
""", |
423
|
|
|
pandoc_latex_tip.main, |
424
|
|
|
) |
425
|
|
|
|
426
|
|
|
def test_div_bulletlist(self): |
427
|
|
|
self.verify_conversion( |
428
|
|
|
""" |
429
|
|
|
--- |
430
|
|
|
pandoc-latex-tip: |
431
|
|
|
- classes: [tip, listing] |
432
|
|
|
icons: |
433
|
|
|
- {name: fa-file-text, color: darksalmon, link: http://www.google.fr} |
434
|
|
|
- fa-comments |
435
|
|
|
size: 36 |
436
|
|
|
position: right |
437
|
|
|
|
438
|
|
|
- classes: [warning] |
439
|
|
|
icons: fa-comments |
440
|
|
|
|
441
|
|
|
- classes: [tip] |
442
|
|
|
position: left |
443
|
|
|
|
444
|
|
|
- classes: [v5.0] |
445
|
|
|
icons: |
446
|
|
|
- name: far-user |
447
|
|
|
color: orange |
448
|
|
|
--- |
449
|
|
|
|
450
|
|
|
::: warning |
451
|
|
|
* a |
452
|
|
|
* b |
453
|
|
|
::: |
454
|
|
|
""", |
455
|
|
|
f""" |
456
|
|
|
\\begin{{itemize}} |
457
|
|
|
\\tightlist |
458
|
|
|
\\item |
459
|
|
|
a |
460
|
|
|
\\checkoddpage%% |
461
|
|
|
\\ifoddpage%% |
462
|
|
|
\\PandocLatexTipOddLeft%% |
463
|
|
|
\\else%% |
464
|
|
|
\\PandocLatexTipEvenLeft%% |
465
|
|
|
\\fi%% |
466
|
|
|
\\marginnote{{\\includegraphics[width=\\linewidth,height=0.25in,keepaspectratio]{{{platformdirs.AppDirs('pandoc_latex_tip').user_cache_dir}/black/fa-comments.png}}}}[0pt]\\vspace{{0cm}}%% |
467
|
|
|
\\item |
468
|
|
|
b |
469
|
|
|
\\end{{itemize}} |
470
|
|
|
""", |
471
|
|
|
pandoc_latex_tip.main, |
472
|
|
|
) |
473
|
|
|
|