-
-
Notifications
You must be signed in to change notification settings - Fork 246
/
test_highlight.py
602 lines (505 loc) · 18 KB
/
test_highlight.py
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
"""Test cases for Highlight."""
from .. import util
class TestHighlightGuess(util.MdCase):
"""Test that highlighting works with guessing."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'guess_lang': True
}
}
def test_guess(self):
"""Test guessing."""
self.check_markdown(
r'''
```
import test
test.test()
```
''',
'''
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">test</span>
<span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">()</span>
</code></pre></div>
''',
True
)
class TestHighlightAutoTitle(util.MdCase):
"""Test title cases."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'auto_title': True
}
}
def test_auto_tile(self):
"""Test auto title."""
self.check_markdown(
r'''
```pycon
>>> import test
```
''',
r'''
<div class="highlight"><span class="filename">Python Console Session</span><pre><span></span><code><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">test</span>
</code></pre></div>
''', # noqa: E501
True
)
class TestHighlightAutoTitleMap(util.MdCase):
"""Test title cases."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'auto_title': True,
"auto_title_map": {
"Python Console Session": "Python"
}
}
}
def test_auto_tile_map(self):
"""Test auto title."""
self.check_markdown(
r'''
```pycon
>>> import test
```
''',
r'''
<div class="highlight"><span class="filename">Python</span><pre><span></span><code><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">test</span>
</code></pre></div>
''', # noqa: E501
True
)
class TestHighlightInline(util.MdCase):
"""Test highlight inline."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'linenums_style': 'pymdownx-inline'
}
}
def test_pymdownx_inline(self):
"""Test new inline mode."""
self.check_markdown(
r'''
```python linenums="1"
import test
test.test()
```
''',
r'''
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="kn">import</span> <span class="nn">test</span>
<span class="linenos" data-linenos="2 "></span><span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">()</span>
</code></pre></div>
''', # noqa: E501
True
)
class TestNoClass(util.MdCase):
"""Test no class."""
extension = ['pymdownx.highlight', 'pymdownx.superfences', 'markdown.extensions.attr_list']
extension_configs = {
'pymdownx.highlight': {
'css_class': ''
}
}
def test_no_class(self):
"""Test with no class."""
self.check_markdown(
r'''
```python
import test
test.test()
```
''',
r'''
<div><pre><span></span><code><span class="kn">import</span> <span class="nn">test</span>
<span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">()</span>
</code></pre></div>
''', # noqa: E501
True
)
def test_no_class_and_user_class(self):
"""Test with no class and user class."""
self.check_markdown(
r'''
```{.python .more}
import test
test.test()
```
''',
r'''
<div class="more"><pre><span></span><code><span class="kn">import</span> <span class="nn">test</span>
<span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">()</span>
</code></pre></div>
''', # noqa: E501
True
)
def test_no_class_and_user_class_linenums(self):
"""Test with no class and user class and table format."""
self.check_markdown(
r'''
```{.python .more linenums="1"}
import test
test.test()
```
''',
r'''
<table class="more table"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
<span class="normal">2</span></pre></div></td><td class="code"><div class="more "><pre><span></span><code><span class="kn">import</span> <span class="nn">test</span>
<span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">()</span>
</code></pre></div>
</td></tr></table>
''', # noqa: E501
True
)
class TestNoClassNoPygments(util.MdCase):
"""Test no class."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'css_class': '',
'use_pygments': False
}
}
def test_no_class_no_pygments(self):
"""Test with no class and no Pygments."""
self.check_markdown(
r'''
```python
import test
test.test()
```
''',
r'''
<pre><code class="language-python">import test
test.test()</code></pre>
''', # noqa: E501
True
)
class TestCustomLangPrefixNoPygments(util.MdCase):
"""Test custom language prefix."""
extension = ['pymdownx.highlight', 'pymdownx.superfences', 'pymdownx.inlinehilite']
extension_configs = {
'pymdownx.highlight': {
'language_prefix': 'lang-',
'use_pygments': False
}
}
def test_custom_prefix_no_pygments(self):
"""Test with custom prefix and no Pygments."""
self.check_markdown(
r'''
```python
import test
test.test()
```
''',
r'''
<pre class="highlight"><code class="lang-python">import test
test.test()</code></pre>
''', # noqa: E501
True
)
def test_custom_prefix_no_pygments_inline(self):
"""Test with custom prefix and no Pygments with inline code."""
self.check_markdown(
'`#!python import test`',
'<p><code class="lang-python highlight">import test</code></p>'
)
class TestNoPygments(util.MdCase):
"""Test no Pygments."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'use_pygments': False
}
}
def test_no_pygments(self):
"""Test with no Pygments."""
self.check_markdown(
r'''
```python
import test
test.test()
```
''',
r'''
<pre class="highlight"><code class="language-python">import test
test.test()</code></pre>
''',
True
)
def test_no_pygments_linenums(self):
"""Test with no Pygments and line numbers."""
self.check_markdown(
r'''
```python linenums="1"
import test
test.test()
```
''',
r'''
<p><code>python linenums="1"
import test
test.test()</code></p>
''',
True
)
class TestNoPygmentsCustomLineClass(util.MdCase):
"""Test no Pygments with custom line number class."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'use_pygments': False,
'linenums_class': 'line-numbers',
'linenums': True
}
}
def test_no_pygments_linenums_custom_class(self):
"""Test with no Pygments and line numbers."""
self.check_markdown(
r'''
Text
import test
test.test()
Text
''',
r'''
<p>Text</p>
<pre class="highlight"><code>import test
test.test()
</code></pre>
<p>Text</p>
''',
True
)
def test_no_pygments_linenums_custom_class_fences(self):
"""Test with no Pygments and line numbers in fences."""
self.check_markdown(
r'''
```python
import test
test.test()
```
''',
r'''
<pre class="highlight"><code class="language-python">import test
test.test()</code></pre>
''',
True
)
class TestHighlightSpecial(util.MdCase):
"""Test highlight global special."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'linenums_style': 'pymdownx-inline',
'linenums_special': 2
}
}
def test_special(self):
"""Test global special mode."""
self.check_markdown(
r'''
```python linenums="1"
import test
test.test()
```
''',
r'''
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="kn">import</span> <span class="nn">test</span>
<span class="linenos special" data-linenos="2 "></span><span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">()</span>
</code></pre></div>
''', # noqa: E501
True
)
def test_special_override(self):
"""Test global special mode override."""
self.check_markdown(
r'''
```python linenums="1 1 1"
import test
test.test()
```
''',
r'''
<div class="highlight"><pre><span></span><code><span class="linenos special" data-linenos="1 "></span><span class="kn">import</span> <span class="nn">test</span>
<span class="linenos special" data-linenos="2 "></span><span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">()</span>
</code></pre></div>
''', # noqa: E501
True
)
class TestDisabledLinenums(util.MdCase):
"""Test with line numbers globally disabled."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'linenums': False
}
}
def test_global_disable(self):
"""Test with line numbers globally disabled."""
self.check_markdown(
r'''
```python linenums="1"
import test
test.test()
```
''',
r'''
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">test</span>
<span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">()</span>
</code></pre></div>
''', # noqa: E501
True
)
class TestDisabledLinenumsNoPygments(util.MdCase):
"""Test with line numbers globally disabled with no Pygments."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'linenums': False,
'use_pygments': False
}
}
def test_global_disable(self):
"""Test with line numbers globally disabled and no Pygments."""
self.check_markdown(
r'''
```python linenums="1"
import test
test.test()
```
''',
r'''
<p><code>python linenums="1"
import test
test.test()</code></p>
''', # noqa: E501
True
)
class TestGlobalLinenums(util.MdCase):
"""Test global line number cases."""
extension = ['pymdownx.highlight', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'linenums': True
}
}
def test_global_line_numbers(self):
"""Test that global line numbers works."""
self.check_markdown(
r'''
```python
import test
test.test()
```
''',
r'''
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">test</span>
<span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">()</span>
</code></pre></div>
</td></tr></table>
''', # noqa: E501
True
)
def test_global_disabling_of_line_numbers(self):
"""Test that global line numbers can be disabled."""
self.check_markdown(
r'''
```{.python linenums="0"}
import test
test.test()
```
''',
r'''
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">test</span>
<span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">()</span>
</code></pre></div>
''', # noqa: E501
True
)
class TestPygmentsLangClass(util.MdCase):
"""Test no Pygments with custom line number class."""
extension = ['pymdownx.highlight', 'pymdownx.inlinehilite', 'pymdownx.superfences']
extension_configs = {
'pymdownx.highlight': {
'pygments_lang_class': True
}
}
def test_superfences(self):
"""Test language classes with SuperFences."""
self.check_markdown(
r'''
```python
import test
```
''',
r'''
<div class="language-python highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">test</span>
</code></pre></div>
''', # noqa: E501
True
)
def test_inlinehilite(self):
"""Test language classes with InlineHilite."""
self.check_markdown(
'''
`#!python import test`
''',
'''
<p><code class="language-python highlight"><span class="kn">import</span> <span class="nn">test</span></code></p>
''', # noqa: E501
True
)
class TestExtendedLang(util.MdCase):
"""Test extended language cases."""
extension = ['pymdownx.highlight', 'pymdownx.superfences', 'pymdownx.inlinehilite']
extension_configs = {
'pymdownx.highlight': {
'extend_pygments_lang': [
{'name': 'php-inline', 'lang': 'php', 'options': {'startinline': True}}
]
}
}
def test_extended_lang_inlinehilite(self):
"""Test extended language in InlineHilite."""
self.check_markdown(
'''
`#!php-inline $a = array("foo" => 0, "bar" => 1);`
''',
'''
<p><code class="highlight"><span class="nv">$a</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s2">"foo"</span> <span class="o">=></span> <span class="mi">0</span><span class="p">,</span> <span class="s2">"bar"</span> <span class="o">=></span> <span class="mi">1</span><span class="p">);</span></code></p>
''', # noqa: E501
True
)
def test_extended_lang_superfences(self):
"""Test extended language in SuperFences."""
self.check_markdown(
'''
```php-inline
$a = array("foo" => 0, "bar" => 1);
```
''',
'''
<div class="highlight"><pre><span></span><code><span class="nv">$a</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s2">"foo"</span> <span class="o">=></span> <span class="mi">0</span><span class="p">,</span> <span class="s2">"bar"</span> <span class="o">=></span> <span class="mi">1</span><span class="p">);</span>
</code></pre></div>
''', # noqa: E501
True
)
def test_extended_lang_case(self):
"""Test extended language in SuperFences."""
self.check_markdown(
'''
```PHP-Inline
$a = array("foo" => 0, "bar" => 1);
```
''',
'''
<div class="highlight"><pre><span></span><code><span class="nv">$a</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s2">"foo"</span> <span class="o">=></span> <span class="mi">0</span><span class="p">,</span> <span class="s2">"bar"</span> <span class="o">=></span> <span class="mi">1</span><span class="p">);</span>
</code></pre></div>
''', # noqa: E501
True
)