| 1 |
"""Using the "tab" Blocks extension, test general cases for Blocks.""" |
| 2 |
from ... import util |
| 3 |
import unittest |
| 4 |
from pymdownx.blocks import block |
| 5 |
import markdown |
| 6 |
|
| 7 |
|
| 8 |
class TestTypeFunctions(unittest.TestCase): |
| 9 |
"""Validate various type functions.""" |
| 10 |
|
| 11 |
def test_type_any(self): |
| 12 |
"""Test `type_any`.""" |
| 13 |
|
| 14 |
self.assertEqual(3, block.type_any(3)) |
| 15 |
self.assertEqual({}, block.type_any({})) |
| 16 |
self.assertEqual('string', block.type_any('string')) |
| 17 |
|
| 18 |
def test_type_number(self): |
| 19 |
"""Test `type_number`.""" |
| 20 |
|
| 21 |
self.assertEqual(3, block.type_number(3)) |
| 22 |
self.assertEqual(3.0, block.type_number(3.0)) |
| 23 |
with self.assertRaises(ValueError): |
| 24 |
block.type_number('string') |
| 25 |
|
| 26 |
def test_type_integer(self): |
| 27 |
"""Test `type_integer`.""" |
| 28 |
|
| 29 |
self.assertEqual(3, block.type_integer(3)) |
| 30 |
self.assertEqual(3, block.type_integer(3.0)) |
| 31 |
with self.assertRaises(ValueError): |
| 32 |
block.type_integer(3.3) |
| 33 |
|
| 34 |
def test_type_ranged_number(self): |
| 35 |
"""Test `type_ranged_number`.""" |
| 36 |
|
| 37 |
self.assertEqual(4.7, block.type_ranged_number(3, 8)(4.7)) |
| 38 |
with self.assertRaises(ValueError): |
| 39 |
block.type_ranged_number(3, 8)(2.7) |
| 40 |
with self.assertRaises(ValueError): |
| 41 |
block.type_ranged_number(3, 8)(9.2) |
| 42 |
self.assertEqual(-4.7, block.type_ranged_number(None, 8)(-4.7)) |
| 43 |
with self.assertRaises(ValueError): |
| 44 |
block.type_ranged_number(None, 8)(9.2) |
| 45 |
self.assertEqual(1004.7, block.type_ranged_number(3, None)(1004.7)) |
| 46 |
with self.assertRaises(ValueError): |
| 47 |
block.type_ranged_number(3, None)(2.3) |
| 48 |
with self.assertRaises(ValueError): |
| 49 |
block.type_ranged_number(3, 8)('string') |
| 50 |
|
| 51 |
def test_type_ranged_integer(self): |
| 52 |
"""Test `type_ranged_integer`.""" |
| 53 |
|
| 54 |
self.assertEqual(4, block.type_ranged_integer(3, 8)(4)) |
| 55 |
self.assertEqual(4, block.type_ranged_integer(3, 8)(4.0)) |
| 56 |
with self.assertRaises(ValueError): |
| 57 |
block.type_ranged_integer(3, 8)(4.3) |
| 58 |
with self.assertRaises(ValueError): |
| 59 |
block.type_ranged_integer(3, 8)(2) |
| 60 |
with self.assertRaises(ValueError): |
| 61 |
block.type_ranged_integer(3, 8)(9) |
| 62 |
|
| 63 |
def test_type_html_identifier(self): |
| 64 |
"""Test `type_html_tag`.""" |
| 65 |
|
| 66 |
self.assertEqual('div', block.type_html_identifier('div')) |
| 67 |
with self.assertRaises(ValueError): |
| 68 |
block.type_html_identifier('3bad') |
| 69 |
|
| 70 |
def test_type_boolean(self): |
| 71 |
"""Test `type_boolean`.""" |
| 72 |
|
| 73 |
self.assertEqual(True, block.type_boolean(True)) |
| 74 |
self.assertEqual(False, block.type_boolean(False)) |
| 75 |
with self.assertRaises(ValueError): |
| 76 |
block.type_boolean(None) |
| 77 |
|
| 78 |
def test_type_ternary(self): |
| 79 |
"""Test `type_ternary`.""" |
| 80 |
|
| 81 |
self.assertEqual(True, block.type_ternary(True)) |
| 82 |
self.assertEqual(False, block.type_ternary(False)) |
| 83 |
self.assertEqual(None, block.type_ternary(None)) |
| 84 |
with self.assertRaises(ValueError): |
| 85 |
block.type_ternary(3) |
| 86 |
|
| 87 |
def test_type_string(self): |
| 88 |
"""Test `type_string`.""" |
| 89 |
|
| 90 |
self.assertEqual('string', block.type_string('string')) |
| 91 |
with self.assertRaises(ValueError): |
| 92 |
block.type_string(3) |
| 93 |
|
| 94 |
def test_type_string_insensitive(self): |
| 95 |
"""Test `type_string_insensitive`.""" |
| 96 |
|
| 97 |
self.assertEqual('string', block.type_string_insensitive('STRING')) |
| 98 |
with self.assertRaises(ValueError): |
| 99 |
block.type_string_insensitive(3) |
| 100 |
|
| 101 |
def test_type_string_in(self): |
| 102 |
"""Test `type_string_in`.""" |
| 103 |
|
| 104 |
self.assertEqual('this', block.type_string_in(['this', 'that'])('this')) |
| 105 |
self.assertEqual('this', block.type_string_in(['this', 'that'])('This')) |
| 106 |
self.assertEqual('this', block.type_string_in(['this', 'that'], insensitive=False)('this')) |
| 107 |
with self.assertRaises(ValueError): |
| 108 |
block.type_string_in(['this', 'that'], insensitive=False)('This') |
| 109 |
with self.assertRaises(ValueError): |
| 110 |
block.type_string_in(['this', 'that'])('bad') |
| 111 |
|
| 112 |
def test_type_string_delimiter(self): |
| 113 |
"""Test `type_string_delimiter`.""" |
| 114 |
|
| 115 |
self.assertEqual(['this', 'that'], block.type_string_delimiter(';')('this; that')) |
| 116 |
self.assertEqual(['this', 'that'], block.type_string_delimiter(' ')('this that')) |
| 117 |
|
| 118 |
def test_type_html_classes(self): |
| 119 |
"""Test `type_html_classes`.""" |
| 120 |
|
| 121 |
self.assertEqual(['this', 'that'], block.type_html_classes('this that')) |
| 122 |
|
| 123 |
def test_type_multi(self): |
| 124 |
"""Test `type_multi`.""" |
| 125 |
|
| 126 |
t = block.type_multi(block.type_ternary, block.type_string_in(['this', 'that'])) |
| 127 |
self.assertEqual(True, t(True)) |
| 128 |
self.assertEqual(False, t(False)) |
| 129 |
self.assertEqual(None, t(None)) |
| 130 |
self.assertEqual('this', t('this')) |
| 131 |
with self.assertRaises(ValueError): |
| 132 |
t(3) |
| 133 |
with self.assertRaises(ValueError): |
| 134 |
t('other') |
| 135 |
with self.assertRaises(ValueError): |
| 136 |
block.type_multi()(True) |
| 137 |
|
| 138 |
|
| 139 |
class TestRegister(unittest.TestCase): |
| 140 |
"""Test registration cases.""" |
| 141 |
|
| 142 |
def test_duplicates(self): |
| 143 |
"""Test duplicates.""" |
| 144 |
|
| 145 |
with self.assertRaises(ValueError): |
| 146 |
markdown.markdown('test', extensions=['pymdownx.blocks.admonition', 'pymdownx.blocks.admonition']) |
| 147 |
|
| 148 |
|
| 149 |
class TestBlockUndefinedOption(util.MdCase): |
| 150 |
"""Test Blocks with undefined options.""" |
| 151 |
|
| 152 |
extension = ['pymdownx.blocks.html', 'pymdownx.blocks.definition'] |
| 153 |
|
| 154 |
def test_undefined_option(self): |
| 155 |
"""An undefined option will cause the block parsing to fail.""" |
| 156 |
|
| 157 |
self.check_markdown( |
| 158 |
R''' |
| 159 |
/// html | div |
| 160 |
option: whatever |
| 161 |
|
| 162 |
content |
| 163 |
/// |
| 164 |
''', |
| 165 |
''' |
| 166 |
<p>/// html | div |
| 167 |
option: whatever</p> |
| 168 |
<p>content |
| 169 |
///</p> |
| 170 |
''', |
| 171 |
True |
| 172 |
) |
| 173 |
|
| 174 |
def test_bad_option(self): |
| 175 |
"""An undefined option will cause the block parsing to fail.""" |
| 176 |
|
| 177 |
self.check_markdown( |
| 178 |
R''' |
| 179 |
/// html | div |
| 180 |
attrs: whatever |
| 181 |
|
| 182 |
content |
| 183 |
/// |
| 184 |
''', |
| 185 |
''' |
| 186 |
<p>/// html | div |
| 187 |
attrs: whatever</p> |
| 188 |
<p>content |
| 189 |
///</p> |
| 190 |
''', |
| 191 |
True |
| 192 |
) |
| 193 |
|
| 194 |
def test_no_arg(self): |
| 195 |
"""Test no options.""" |
| 196 |
|
| 197 |
self.check_markdown( |
| 198 |
R''' |
| 199 |
/// html |
| 200 |
attrs: whatever |
| 201 |
|
| 202 |
content |
| 203 |
/// |
| 204 |
''', |
| 205 |
''' |
| 206 |
<p>/// html |
| 207 |
attrs: whatever</p> |
| 208 |
<p>content |
| 209 |
///</p> |
| 210 |
''', |
| 211 |
True |
| 212 |
) |
| 213 |
|
| 214 |
def test_too_many_args(self): |
| 215 |
"""Test too many options.""" |
| 216 |
|
| 217 |
self.check_markdown( |
| 218 |
R''' |
| 219 |
/// define |
| 220 |
option: whatever |
| 221 |
|
| 222 |
content |
| 223 |
/// |
| 224 |
''', |
| 225 |
''' |
| 226 |
<p>/// define |
| 227 |
option: whatever</p> |
| 228 |
<p>content |
| 229 |
///</p> |
| 230 |
''', |
| 231 |
True |
| 232 |
) |
| 233 |
|
| 234 |
def test_bad_frontmatter(self): |
| 235 |
"""Test bad frontmatter.""" |
| 236 |
|
| 237 |
self.check_markdown( |
| 238 |
R''' |
| 239 |
/// define |
| 240 |
bad() |
| 241 |
|
| 242 |
content |
| 243 |
/// |
| 244 |
''', |
| 245 |
''' |
| 246 |
<p>/// define |
| 247 |
bad()</p> |
| 248 |
<p>content |
| 249 |
///</p> |
| 250 |
''', |
| 251 |
True |
| 252 |
) |
| 253 |
|
| 254 |
def test_bad_frontmatter2(self): |
| 255 |
"""Test bad frontmatter.""" |
| 256 |
|
| 257 |
self.check_markdown( |
| 258 |
R''' |
| 259 |
/// define |
| 260 |
& |
| 261 |
|
| 262 |
content |
| 263 |
/// |
| 264 |
''', |
| 265 |
''' |
| 266 |
<p>/// define |
| 267 |
&</p> |
| 268 |
<p>content |
| 269 |
///</p> |
| 270 |
''', |
| 271 |
True |
| 272 |
) |
| 273 |
|
| 274 |
def test_commented_frontmatter(self): |
| 275 |
"""Test commented frontmatter.""" |
| 276 |
|
| 277 |
self.check_markdown( |
| 278 |
R''' |
| 279 |
/// html | div |
| 280 |
# attrs: {class: test} |
| 281 |
|
| 282 |
content |
| 283 |
/// |
| 284 |
''', |
| 285 |
''' |
| 286 |
<div> |
| 287 |
<p>content</p> |
| 288 |
</div> |
| 289 |
''', |
| 290 |
True |
| 291 |
) |
| 292 |
|
| 293 |
|
| 294 |
class TestCodeHandling(util.MdCase): |
| 295 |
"""Test some code related cases.""" |
| 296 |
|
| 297 |
extension = ['pymdownx.blocks.html', 'pymdownx.superfences'] |
| 298 |
|
| 299 |
def test_superfence_block(self): |
| 300 |
"""Test blocks with fenced code content.""" |
| 301 |
|
| 302 |
self.check_markdown( |
| 303 |
R''' |
| 304 |
/// html | div |
| 305 |
```python |
| 306 |
import foo |
| 307 |
``` |
| 308 |
/// |
| 309 |
''', |
| 310 |
''' |
| 311 |
<div> |
| 312 |
<div class="highlight"><pre><span></span><code><span class="kn">import</span><span class="w"> </span><span class="nn">foo</span> |
| 313 |
</code></pre></div> |
| 314 |
</div> |
| 315 |
''', # noqa: E501 |
| 316 |
True |
| 317 |
) |
| 318 |
|
| 319 |
def test_superfence_inline(self): |
| 320 |
"""Test blocks with fenced code content.""" |
| 321 |
|
| 322 |
self.check_markdown( |
| 323 |
R''' |
| 324 |
/// html | span |
| 325 |
```python |
| 326 |
import foo |
| 327 |
``` |
| 328 |
|
| 329 |
Other content |
| 330 |
/// |
| 331 |
''', |
| 332 |
''' |
| 333 |
<span><code>python |
| 334 |
import foo</code> |
| 335 |
|
| 336 |
Other content</span> |
| 337 |
''', |
| 338 |
True |
| 339 |
) |
| 340 |
|
| 341 |
|
| 342 |
class TestAttributes(util.MdCase): |
| 343 |
"""Test Blocks tab cases.""" |
| 344 |
|
| 345 |
extension = ['pymdownx.blocks.admonition'] |
| 346 |
|
| 347 |
def test_attributes(self): |
| 348 |
"""Test attributes.""" |
| 349 |
|
| 350 |
self.check_markdown( |
| 351 |
R''' |
| 352 |
/// admonition | Title |
| 353 |
attrs: {class: some classes, id: an-id, name: some value} |
| 354 |
|
| 355 |
content |
| 356 |
/// |
| 357 |
''', |
| 358 |
''' |
| 359 |
<div class="admonition some classes" id="an-id" name="some value"> |
| 360 |
<p class="admonition-title">Title</p> |
| 361 |
<p>content</p> |
| 362 |
</div> |
| 363 |
''', |
| 364 |
True |
| 365 |
) |
| 366 |
|
| 367 |
def test_bad_attributes(self): |
| 368 |
"""Test no attributes.""" |
| 369 |
|
| 370 |
self.check_markdown( |
| 371 |
R''' |
| 372 |
/// admonition | Title |
| 373 |
attrs: {'+': 'value'} |
| 374 |
content |
| 375 |
/// |
| 376 |
''', |
| 377 |
''' |
| 378 |
<p>/// admonition | Title |
| 379 |
attrs: {'+': 'value'} |
| 380 |
content |
| 381 |
///</p> |
| 382 |
''', |
| 383 |
True |
| 384 |
) |
| 385 |
|
| 386 |
|
| 387 |
class TestNestedBlocksAndLists(util.MdCase): |
| 388 |
"""Test Nested blocks and lists.""" |
| 389 |
|
| 390 |
extension = ['pymdownx.blocks.tab', 'pymdownx.blocks.html'] |
| 391 |
extension_configs = { |
| 392 |
'pymdownx.blocks.tab': {'alternate_style': True} |
| 393 |
} |
| 394 |
|
| 395 |
def test_nested_blocks_in_lists(self): |
| 396 |
"""Test a nested blocks case with lists.""" |
| 397 |
|
| 398 |
self.check_markdown( |
| 399 |
R""" |
| 400 |
//// html | div.my-div |
| 401 |
|
| 402 |
- List |
| 403 |
|
| 404 |
- List |
| 405 |
|
| 406 |
/// tab | TEST1 |
| 407 |
|
| 408 |
Content |
| 409 |
|
| 410 |
/// |
| 411 |
|
| 412 |
/// tab | TEST2 |
| 413 |
|
| 414 |
- A list |
| 415 |
|
| 416 |
Paragraph |
| 417 |
|
| 418 |
Code |
| 419 |
|
| 420 |
/// |
| 421 |
|
| 422 |
//// |
| 423 |
""", |
| 424 |
""" |
| 425 |
<div class="my-div"> |
| 426 |
<ul> |
| 427 |
<li> |
| 428 |
<p>List</p> |
| 429 |
<ul> |
| 430 |
<li> |
| 431 |
<p>List</p> |
| 432 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:2"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">TEST1</label><label for="__tabbed_1_2">TEST2</label></div> |
| 433 |
<div class="tabbed-content"> |
| 434 |
<div class="tabbed-block"> |
| 435 |
<p>Content</p> |
| 436 |
</div> |
| 437 |
<div class="tabbed-block"> |
| 438 |
<ul> |
| 439 |
<li> |
| 440 |
<p>A list</p> |
| 441 |
<p>Paragraph</p> |
| 442 |
<pre><code>Code |
| 443 |
</code></pre> |
| 444 |
</li> |
| 445 |
</ul> |
| 446 |
</div> |
| 447 |
</div> |
| 448 |
</div> |
| 449 |
</li> |
| 450 |
</ul> |
| 451 |
</li> |
| 452 |
</ul> |
| 453 |
</div> |
| 454 |
""", # noqa: E501 |
| 455 |
True |
| 456 |
) |
| 457 |
|
| 458 |
|
| 459 |
class TestBlocksMdInHTML(util.MdCase): |
| 460 |
"""Test blocks with `md_in_html`.""" |
| 461 |
|
| 462 |
extension = ['pymdownx.blocks.tab', 'pymdownx.blocks.html', 'markdown.extensions.md_in_html'] |
| 463 |
extension_configs = { |
| 464 |
'pymdownx.blocks.tab': {'alternate_style': True} |
| 465 |
} |
| 466 |
|
| 467 |
def test_md_in_html_inserted_correctly(self): |
| 468 |
"""Test that `md_in_html` inserts under the correct target.""" |
| 469 |
|
| 470 |
self.check_markdown( |
| 471 |
R""" |
| 472 |
//// html | div.my-div |
| 473 |
|
| 474 |
/// tab | TEST |
| 475 |
<div class="mf-generated" markdown> |
| 476 |
Hello I'm in a div which can contain **markdown**! |
| 477 |
</div> |
| 478 |
/// |
| 479 |
|
| 480 |
//// |
| 481 |
""", |
| 482 |
""" |
| 483 |
<div class="my-div"> |
| 484 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">TEST</label></div> |
| 485 |
<div class="tabbed-content"> |
| 486 |
<div class="tabbed-block"> |
| 487 |
<div class="mf-generated"> |
| 488 |
<p>Hello I'm in a div which can contain <strong>markdown</strong>!</p> |
| 489 |
</div> |
| 490 |
</div> |
| 491 |
</div> |
| 492 |
</div> |
| 493 |
</div> |
| 494 |
""", # noqa: E501 |
| 495 |
True |
| 496 |
) |
| 497 |
|
| 498 |
|
| 499 |
class TestBlocksTab(util.MdCase): |
| 500 |
"""Test Blocks tab cases.""" |
| 501 |
|
| 502 |
extension = [ |
| 503 |
'admonition', |
| 504 |
'pymdownx.blocks.tab', |
| 505 |
'pymdownx.superfences', |
| 506 |
'markdown.extensions.def_list', |
| 507 |
'pymdownx.details' |
| 508 |
] |
| 509 |
extension_configs = { |
| 510 |
'pymdownx.blocks.tab': {'alternate_style': True} |
| 511 |
} |
| 512 |
|
| 513 |
def test_with_preceding_text(self): |
| 514 |
"""Test content directly before tabs.""" |
| 515 |
|
| 516 |
expected = r''' |
| 517 |
<p>foo |
| 518 |
<strong>foo</strong></p> |
| 519 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab</label></div> |
| 520 |
<div class="tabbed-content"> |
| 521 |
<div class="tabbed-block"></div> |
| 522 |
</div> |
| 523 |
</div> |
| 524 |
''' # noqa: E501 |
| 525 |
|
| 526 |
self.check_markdown( |
| 527 |
R''' |
| 528 |
foo |
| 529 |
**foo** |
| 530 |
/// tab | Tab |
| 531 |
/// |
| 532 |
''', |
| 533 |
expected, |
| 534 |
True |
| 535 |
) |
| 536 |
|
| 537 |
def test_nested_tabbed(self): |
| 538 |
"""Test nested tabbed.""" |
| 539 |
|
| 540 |
self.check_markdown( |
| 541 |
R''' |
| 542 |
//// tab | Tab |
| 543 |
Some *content* |
| 544 |
|
| 545 |
/// tab | Tab A |
| 546 |
- item 1 |
| 547 |
|
| 548 |
- item 2 |
| 549 |
/// |
| 550 |
|
| 551 |
/// tab | Tab B |
| 552 |
- item A |
| 553 |
|
| 554 |
- item B |
| 555 |
/// |
| 556 |
//// |
| 557 |
|
| 558 |
/// tab | Another Tab |
| 559 |
|
| 560 |
Some more content. |
| 561 |
/// |
| 562 |
''', |
| 563 |
r''' |
| 564 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:2"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab</label><label for="__tabbed_1_2">Another Tab</label></div> |
| 565 |
<div class="tabbed-content"> |
| 566 |
<div class="tabbed-block"> |
| 567 |
<p>Some <em>content</em></p> |
| 568 |
<div class="tabbed-set tabbed-alternate" data-tabs="2:2"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><input id="__tabbed_2_2" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">Tab A</label><label for="__tabbed_2_2">Tab B</label></div> |
| 569 |
<div class="tabbed-content"> |
| 570 |
<div class="tabbed-block"> |
| 571 |
<ul> |
| 572 |
<li> |
| 573 |
<p>item 1</p> |
| 574 |
</li> |
| 575 |
<li> |
| 576 |
<p>item 2</p> |
| 577 |
</li> |
| 578 |
</ul> |
| 579 |
</div> |
| 580 |
<div class="tabbed-block"> |
| 581 |
<ul> |
| 582 |
<li> |
| 583 |
<p>item A</p> |
| 584 |
</li> |
| 585 |
<li> |
| 586 |
<p>item B</p> |
| 587 |
</li> |
| 588 |
</ul> |
| 589 |
</div> |
| 590 |
</div> |
| 591 |
</div> |
| 592 |
</div> |
| 593 |
<div class="tabbed-block"> |
| 594 |
<p>Some more content.</p> |
| 595 |
</div> |
| 596 |
</div> |
| 597 |
</div> |
| 598 |
''', # noqa: E501 |
| 599 |
True |
| 600 |
) |
| 601 |
|
| 602 |
def test_tabbed_break(self): |
| 603 |
"""Test that tabs are properly terminated on blocks that are not under the tab.""" |
| 604 |
|
| 605 |
self.check_markdown( |
| 606 |
r''' |
| 607 |
/// tab | Tab |
| 608 |
Some *content* |
| 609 |
|
| 610 |
And more `content`. |
| 611 |
/// |
| 612 |
Content |
| 613 |
''', |
| 614 |
r''' |
| 615 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab</label></div> |
| 616 |
<div class="tabbed-content"> |
| 617 |
<div class="tabbed-block"> |
| 618 |
<p>Some <em>content</em></p> |
| 619 |
<p>And more <code>content</code>.</p> |
| 620 |
</div> |
| 621 |
</div> |
| 622 |
</div> |
| 623 |
<p>Content</p> |
| 624 |
''', # noqa: E501 |
| 625 |
True |
| 626 |
) |
| 627 |
|
| 628 |
def test_with_lists(self): |
| 629 |
"""Test with lists.""" |
| 630 |
|
| 631 |
self.check_markdown( |
| 632 |
''' |
| 633 |
- List |
| 634 |
|
| 635 |
/// tab | Tab |
| 636 |
- Paragraph |
| 637 |
|
| 638 |
Paragraph |
| 639 |
/// |
| 640 |
''', |
| 641 |
|
| 642 |
''' |
| 643 |
<ul> |
| 644 |
<li> |
| 645 |
<p>List</p> |
| 646 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab</label></div> |
| 647 |
<div class="tabbed-content"> |
| 648 |
<div class="tabbed-block"> |
| 649 |
<ul> |
| 650 |
<li> |
| 651 |
<p>Paragraph</p> |
| 652 |
<p>Paragraph</p> |
| 653 |
</li> |
| 654 |
</ul> |
| 655 |
</div> |
| 656 |
</div> |
| 657 |
</div> |
| 658 |
</li> |
| 659 |
</ul> |
| 660 |
''', # noqa: E501 |
| 661 |
True |
| 662 |
) |
| 663 |
|
| 664 |
def test_with_big_lists(self): |
| 665 |
"""Test details with a longer list.""" |
| 666 |
|
| 667 |
self.check_markdown( |
| 668 |
''' |
| 669 |
- List |
| 670 |
|
| 671 |
/// tab | Tab |
| 672 |
- Paragraph |
| 673 |
|
| 674 |
Paragraph |
| 675 |
|
| 676 |
- Paragraph |
| 677 |
|
| 678 |
paragraph |
| 679 |
/// |
| 680 |
''', |
| 681 |
''' |
| 682 |
<ul> |
| 683 |
<li> |
| 684 |
<p>List</p> |
| 685 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab</label></div> |
| 686 |
<div class="tabbed-content"> |
| 687 |
<div class="tabbed-block"> |
| 688 |
<ul> |
| 689 |
<li> |
| 690 |
<p>Paragraph</p> |
| 691 |
<p>Paragraph</p> |
| 692 |
</li> |
| 693 |
<li> |
| 694 |
<p>Paragraph</p> |
| 695 |
<p>paragraph</p> |
| 696 |
</li> |
| 697 |
</ul> |
| 698 |
</div> |
| 699 |
</div> |
| 700 |
</div> |
| 701 |
</li> |
| 702 |
</ul> |
| 703 |
''', # noqa: E501 |
| 704 |
True |
| 705 |
) |
| 706 |
|
| 707 |
def test_with_complex_lists(self): |
| 708 |
"""Test details in a complex list scenario.""" |
| 709 |
|
| 710 |
self.check_markdown( |
| 711 |
''' |
| 712 |
- List |
| 713 |
|
| 714 |
/// tab | Tab |
| 715 |
- Paragraph |
| 716 |
|
| 717 |
//// tab | Tab |
| 718 |
1. Paragraph |
| 719 |
|
| 720 |
Paragraph |
| 721 |
|
| 722 |
Paragraph |
| 723 |
//// |
| 724 |
/// |
| 725 |
''', |
| 726 |
''' |
| 727 |
<ul> |
| 728 |
<li> |
| 729 |
<p>List</p> |
| 730 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab</label></div> |
| 731 |
<div class="tabbed-content"> |
| 732 |
<div class="tabbed-block"> |
| 733 |
<ul> |
| 734 |
<li> |
| 735 |
<p>Paragraph</p> |
| 736 |
<div class="tabbed-set tabbed-alternate" data-tabs="2:1"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">Tab</label></div> |
| 737 |
<div class="tabbed-content"> |
| 738 |
<div class="tabbed-block"> |
| 739 |
<ol> |
| 740 |
<li> |
| 741 |
<p>Paragraph</p> |
| 742 |
<p>Paragraph</p> |
| 743 |
<p>Paragraph</p> |
| 744 |
</li> |
| 745 |
</ol> |
| 746 |
</div> |
| 747 |
</div> |
| 748 |
</div> |
| 749 |
</li> |
| 750 |
</ul> |
| 751 |
</div> |
| 752 |
</div> |
| 753 |
</div> |
| 754 |
</li> |
| 755 |
</ul> |
| 756 |
''', # noqa: E501 |
| 757 |
True |
| 758 |
) |
| 759 |
|
| 760 |
def test_definition_list(self): |
| 761 |
"""Test with definition list.""" |
| 762 |
|
| 763 |
self.check_markdown( |
| 764 |
''' |
| 765 |
- List |
| 766 |
|
| 767 |
/// tab | Tab |
| 768 |
Term |
| 769 |
|
| 770 |
: Definition |
| 771 |
|
| 772 |
More text |
| 773 |
|
| 774 |
: Another |
| 775 |
definition |
| 776 |
|
| 777 |
Even more text |
| 778 |
/// |
| 779 |
''', |
| 780 |
''' |
| 781 |
<ul> |
| 782 |
<li> |
| 783 |
<p>List</p> |
| 784 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab</label></div> |
| 785 |
<div class="tabbed-content"> |
| 786 |
<div class="tabbed-block"> |
| 787 |
<dl> |
| 788 |
<dt>Term</dt> |
| 789 |
<dd> |
| 790 |
<p>Definition</p> |
| 791 |
<p>More text</p> |
| 792 |
</dd> |
| 793 |
<dd> |
| 794 |
<p>Another |
| 795 |
definition</p> |
| 796 |
<p>Even more text</p> |
| 797 |
</dd> |
| 798 |
</dl> |
| 799 |
</div> |
| 800 |
</div> |
| 801 |
</div> |
| 802 |
</li> |
| 803 |
</ul> |
| 804 |
''', # noqa: E501 |
| 805 |
True |
| 806 |
) |
| 807 |
|
| 808 |
def test_with_details(self): |
| 809 |
"""Test with definition list.""" |
| 810 |
|
| 811 |
self.check_markdown( |
| 812 |
''' |
| 813 |
/// tab | Output |
| 814 |
|
| 815 |
???+ note "Open styled details" |
| 816 |
|
| 817 |
??? danger "Nested details!" |
| 818 |
And more content again. |
| 819 |
/// |
| 820 |
''', |
| 821 |
''' |
| 822 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Output</label></div> |
| 823 |
<div class="tabbed-content"> |
| 824 |
<div class="tabbed-block"> |
| 825 |
<details class="note" open="open"> |
| 826 |
<summary>Open styled details</summary> |
| 827 |
<details class="danger"> |
| 828 |
<summary>Nested details!</summary> |
| 829 |
<p>And more content again.</p> |
| 830 |
</details> |
| 831 |
</details> |
| 832 |
</div> |
| 833 |
</div> |
| 834 |
</div> |
| 835 |
''', # noqa: E501 |
| 836 |
True |
| 837 |
) |
| 838 |
|
| 839 |
def test_tabbed_complex_list(self): |
| 840 |
"""Test tabbed complex list scenario.""" |
| 841 |
|
| 842 |
self.check_markdown( |
| 843 |
''' |
| 844 |
/// tab | Tab with loose lists |
| 845 |
- Parent 1 |
| 846 |
|
| 847 |
- Child 1 |
| 848 |
- Child 2 |
| 849 |
/// |
| 850 |
''', |
| 851 |
''' |
| 852 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab with loose lists</label></div> |
| 853 |
<div class="tabbed-content"> |
| 854 |
<div class="tabbed-block"> |
| 855 |
<ul> |
| 856 |
<li> |
| 857 |
<p>Parent 1</p> |
| 858 |
<ul> |
| 859 |
<li>Child 1</li> |
| 860 |
<li>Child 2</li> |
| 861 |
</ul> |
| 862 |
</li> |
| 863 |
</ul> |
| 864 |
</div> |
| 865 |
</div> |
| 866 |
</div> |
| 867 |
''', # noqa: E501 |
| 868 |
True |
| 869 |
) |
| 870 |
|
| 871 |
def test_tabbed_complex_list_unindented_content(self): |
| 872 |
"""Test tabbed complex list scenario with un-indented content.""" |
| 873 |
|
| 874 |
self.check_markdown( |
| 875 |
''' |
| 876 |
/// tab | Tab with loose lists |
| 877 |
- Parent 1 |
| 878 |
|
| 879 |
- Child 1 |
| 880 |
- Child 2 |
| 881 |
/// |
| 882 |
- Parent 2 |
| 883 |
''', |
| 884 |
''' |
| 885 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab with loose lists</label></div> |
| 886 |
<div class="tabbed-content"> |
| 887 |
<div class="tabbed-block"> |
| 888 |
<ul> |
| 889 |
<li> |
| 890 |
<p>Parent 1</p> |
| 891 |
<ul> |
| 892 |
<li>Child 1</li> |
| 893 |
<li>Child 2</li> |
| 894 |
</ul> |
| 895 |
</li> |
| 896 |
</ul> |
| 897 |
</div> |
| 898 |
</div> |
| 899 |
</div> |
| 900 |
<ul> |
| 901 |
<li>Parent 2</li> |
| 902 |
</ul> |
| 903 |
''', # noqa: E501 |
| 904 |
True |
| 905 |
) |
| 906 |
|
| 907 |
def test_nesting_with_legacy_style(self): |
| 908 |
"""Test nesting with legacy style admonitions.""" |
| 909 |
|
| 910 |
self.check_markdown( |
| 911 |
''' |
| 912 |
!!! note "Admonition 1" |
| 913 |
|
| 914 |
Admonition 1 |
| 915 |
|
| 916 |
/// tab | Tab 1 |
| 917 |
|
| 918 |
Test tab 1 |
| 919 |
|
| 920 |
!!! note "Admonition 2" |
| 921 |
|
| 922 |
Admonition 2 |
| 923 |
|
| 924 |
//// tab | Tab 2 |
| 925 |
|
| 926 |
Test tab 2 |
| 927 |
|
| 928 |
!!! note "Admonition 3" |
| 929 |
|
| 930 |
Admonition 3 |
| 931 |
|
| 932 |
//// |
| 933 |
/// |
| 934 |
''', |
| 935 |
''' |
| 936 |
<div class="admonition note"> |
| 937 |
<p class="admonition-title">Admonition 1</p> |
| 938 |
<p>Admonition 1</p> |
| 939 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab 1</label></div> |
| 940 |
<div class="tabbed-content"> |
| 941 |
<div class="tabbed-block"> |
| 942 |
<p>Test tab 1</p> |
| 943 |
<div class="admonition note"> |
| 944 |
<p class="admonition-title">Admonition 2</p> |
| 945 |
<p>Admonition 2</p> |
| 946 |
<div class="tabbed-set tabbed-alternate" data-tabs="2:1"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">Tab 2</label></div> |
| 947 |
<div class="tabbed-content"> |
| 948 |
<div class="tabbed-block"> |
| 949 |
<p>Test tab 2</p> |
| 950 |
<div class="admonition note"> |
| 951 |
<p class="admonition-title">Admonition 3</p> |
| 952 |
<p>Admonition 3</p> |
| 953 |
</div> |
| 954 |
</div> |
| 955 |
</div> |
| 956 |
</div> |
| 957 |
</div> |
| 958 |
</div> |
| 959 |
</div> |
| 960 |
</div> |
| 961 |
</div> |
| 962 |
''', # noqa: E501 |
| 963 |
True |
| 964 |
) |