| 1 |
"""Test cases for Details.""" |
| 2 |
from .. import util |
| 3 |
|
| 4 |
|
| 5 |
class TestDetails(util.MdCase): |
| 6 |
"""Test Details.""" |
| 7 |
|
| 8 |
extension = ['pymdownx.details', 'markdown.extensions.def_list'] |
| 9 |
extension_configs = { |
| 10 |
'pymdownx.blocks': { |
| 11 |
'blocks': ['pymdownx.blocks.details:Details'] |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
def test_with_preceding_text(self): |
| 16 |
"""Test content right before details.""" |
| 17 |
|
| 18 |
expected = r''' |
| 19 |
<p>foo |
| 20 |
<strong>foo</strong></p> |
| 21 |
<details class="note"> |
| 22 |
<summary>Details</summary> |
| 23 |
</details> |
| 24 |
''' |
| 25 |
|
| 26 |
self.check_markdown( |
| 27 |
R''' |
| 28 |
foo |
| 29 |
**foo** |
| 30 |
??? note "Details" |
| 31 |
''', |
| 32 |
expected, |
| 33 |
True |
| 34 |
) |
| 35 |
|
| 36 |
def test_nested(self): |
| 37 |
"""Test nested.""" |
| 38 |
|
| 39 |
expected = r''' |
| 40 |
<details> |
| 41 |
<summary>details</summary> |
| 42 |
<p>content</p> |
| 43 |
<details open="open"> |
| 44 |
<summary>open nested details</summary> |
| 45 |
<p>content</p> |
| 46 |
<p>more content</p> |
| 47 |
</details> |
| 48 |
</details> |
| 49 |
''' |
| 50 |
|
| 51 |
self.check_markdown( |
| 52 |
r''' |
| 53 |
??? "details" |
| 54 |
content |
| 55 |
|
| 56 |
???+ "open nested details" |
| 57 |
content |
| 58 |
|
| 59 |
more content |
| 60 |
''', |
| 61 |
expected, |
| 62 |
True |
| 63 |
) |
| 64 |
|
| 65 |
def test_class(self): |
| 66 |
"""Test class.""" |
| 67 |
|
| 68 |
expected = r''' |
| 69 |
<details class="optional-class"> |
| 70 |
<summary>details with class</summary> |
| 71 |
<p>content</p> |
| 72 |
</details> |
| 73 |
''' |
| 74 |
|
| 75 |
self.check_markdown( |
| 76 |
r''' |
| 77 |
??? optional-class "details with class" |
| 78 |
content |
| 79 |
''', |
| 80 |
expected, |
| 81 |
True |
| 82 |
) |
| 83 |
|
| 84 |
def test_multiple_classes(self): |
| 85 |
"""Test multiple classes.""" |
| 86 |
|
| 87 |
expected = r''' |
| 88 |
<details class="multiple optional-class"> |
| 89 |
<summary>details with multiple class</summary> |
| 90 |
<p>content</p> |
| 91 |
</details> |
| 92 |
''' |
| 93 |
|
| 94 |
self.check_markdown( |
| 95 |
r''' |
| 96 |
??? multiple optional-class "details with multiple class" |
| 97 |
content |
| 98 |
''', |
| 99 |
expected, |
| 100 |
True |
| 101 |
) |
| 102 |
|
| 103 |
def test_only_class(self): |
| 104 |
"""Test only class.""" |
| 105 |
|
| 106 |
expected = r''' |
| 107 |
<details class="only-class"> |
| 108 |
<summary>Only-class</summary> |
| 109 |
<p>content</p> |
| 110 |
</details> |
| 111 |
''' |
| 112 |
|
| 113 |
self.check_markdown( |
| 114 |
r''' |
| 115 |
??? only-class |
| 116 |
content |
| 117 |
''', |
| 118 |
expected, |
| 119 |
True |
| 120 |
) |
| 121 |
|
| 122 |
def test_only_multiple_classes(self): |
| 123 |
"""Test only multiple classes.""" |
| 124 |
|
| 125 |
expected = r''' |
| 126 |
<details class="multiple classes"> |
| 127 |
<summary>Multiple</summary> |
| 128 |
<p>content</p> |
| 129 |
</details> |
| 130 |
''' |
| 131 |
|
| 132 |
self.check_markdown( |
| 133 |
r''' |
| 134 |
??? multiple classes |
| 135 |
content |
| 136 |
''', |
| 137 |
expected, |
| 138 |
True |
| 139 |
) |
| 140 |
|
| 141 |
def test_content_after(self): |
| 142 |
"""Test content after details.""" |
| 143 |
|
| 144 |
expected = r''' |
| 145 |
<details> |
| 146 |
<summary>details end test</summary> |
| 147 |
<p>content</p> |
| 148 |
</details> |
| 149 |
<p>other content</p> |
| 150 |
''' |
| 151 |
|
| 152 |
self.check_markdown( |
| 153 |
r''' |
| 154 |
??? "details end test" |
| 155 |
content |
| 156 |
other content |
| 157 |
''', |
| 158 |
expected, |
| 159 |
True |
| 160 |
) |
| 161 |
|
| 162 |
def test_relaxed_spacing(self): |
| 163 |
"""Test relaxed spacing.""" |
| 164 |
|
| 165 |
expected = r''' |
| 166 |
<details class="relaxed spacing"> |
| 167 |
<summary>Title</summary> |
| 168 |
<p>content</p> |
| 169 |
</details> |
| 170 |
''' |
| 171 |
|
| 172 |
self.check_markdown( |
| 173 |
r''' |
| 174 |
???relaxed spacing "Title" |
| 175 |
content |
| 176 |
''', |
| 177 |
expected, |
| 178 |
True |
| 179 |
) |
| 180 |
|
| 181 |
def test_relaxed_spacing_no_title(self): |
| 182 |
"""Test relaxed spacing and no title.""" |
| 183 |
|
| 184 |
expected = r''' |
| 185 |
<details class="relaxed spacing no title"> |
| 186 |
<summary>Relaxed</summary> |
| 187 |
<p>content</p> |
| 188 |
</details> |
| 189 |
''' |
| 190 |
|
| 191 |
self.check_markdown( |
| 192 |
r''' |
| 193 |
???relaxed spacing no title |
| 194 |
content |
| 195 |
''', |
| 196 |
expected, |
| 197 |
True |
| 198 |
) |
| 199 |
|
| 200 |
def test_with_lists(self): |
| 201 |
"""Test with lists.""" |
| 202 |
|
| 203 |
self.check_markdown( |
| 204 |
''' |
| 205 |
- List |
| 206 |
|
| 207 |
??? note "Details" |
| 208 |
|
| 209 |
- Paragraph |
| 210 |
|
| 211 |
Paragraph |
| 212 |
''', |
| 213 |
|
| 214 |
''' |
| 215 |
<ul> |
| 216 |
<li> |
| 217 |
<p>List</p> |
| 218 |
<details class="note"> |
| 219 |
<summary>Details</summary> |
| 220 |
<ul> |
| 221 |
<li> |
| 222 |
<p>Paragraph</p> |
| 223 |
<p>Paragraph</p> |
| 224 |
</li> |
| 225 |
</ul> |
| 226 |
</details> |
| 227 |
</li> |
| 228 |
</ul> |
| 229 |
''', |
| 230 |
True |
| 231 |
) |
| 232 |
|
| 233 |
def test_with_big_lists(self): |
| 234 |
"""Test details with a longer list.""" |
| 235 |
|
| 236 |
self.check_markdown( |
| 237 |
''' |
| 238 |
- List |
| 239 |
|
| 240 |
??? note "Details" |
| 241 |
|
| 242 |
- Paragraph |
| 243 |
|
| 244 |
Paragraph |
| 245 |
|
| 246 |
- Paragraph |
| 247 |
|
| 248 |
paragraph |
| 249 |
''', |
| 250 |
''' |
| 251 |
<ul> |
| 252 |
<li> |
| 253 |
<p>List</p> |
| 254 |
<details class="note"> |
| 255 |
<summary>Details</summary> |
| 256 |
<ul> |
| 257 |
<li> |
| 258 |
<p>Paragraph</p> |
| 259 |
<p>Paragraph</p> |
| 260 |
</li> |
| 261 |
<li> |
| 262 |
<p>Paragraph</p> |
| 263 |
<p>paragraph</p> |
| 264 |
</li> |
| 265 |
</ul> |
| 266 |
</details> |
| 267 |
</li> |
| 268 |
</ul> |
| 269 |
''', |
| 270 |
True |
| 271 |
) |
| 272 |
|
| 273 |
def test_with_complex_lists(self): |
| 274 |
"""Test details in a complex list scenario.""" |
| 275 |
|
| 276 |
self.check_markdown( |
| 277 |
''' |
| 278 |
- List |
| 279 |
|
| 280 |
??? note "Details" |
| 281 |
|
| 282 |
- Paragraph |
| 283 |
|
| 284 |
??? note "Details" |
| 285 |
|
| 286 |
1. Paragraph |
| 287 |
|
| 288 |
Paragraph |
| 289 |
''', |
| 290 |
''' |
| 291 |
<ul> |
| 292 |
<li> |
| 293 |
<p>List</p> |
| 294 |
<details class="note"> |
| 295 |
<summary>Details</summary> |
| 296 |
<ul> |
| 297 |
<li> |
| 298 |
<p>Paragraph</p> |
| 299 |
<details class="note"> |
| 300 |
<summary>Details</summary> |
| 301 |
<ol> |
| 302 |
<li> |
| 303 |
<p>Paragraph</p> |
| 304 |
<p>Paragraph</p> |
| 305 |
</li> |
| 306 |
</ol> |
| 307 |
</details> |
| 308 |
</li> |
| 309 |
</ul> |
| 310 |
</details> |
| 311 |
</li> |
| 312 |
</ul> |
| 313 |
''', |
| 314 |
True |
| 315 |
) |
| 316 |
|
| 317 |
def test_definition_list(self): |
| 318 |
"""Test with definition list.""" |
| 319 |
|
| 320 |
self.check_markdown( |
| 321 |
''' |
| 322 |
- List |
| 323 |
|
| 324 |
??? note "Details" |
| 325 |
|
| 326 |
Term |
| 327 |
|
| 328 |
: Definition |
| 329 |
|
| 330 |
More text |
| 331 |
|
| 332 |
: Another |
| 333 |
definition |
| 334 |
|
| 335 |
Even more text |
| 336 |
''', |
| 337 |
''' |
| 338 |
<ul> |
| 339 |
<li> |
| 340 |
<p>List</p> |
| 341 |
<details class="note"> |
| 342 |
<summary>Details</summary> |
| 343 |
<dl> |
| 344 |
<dt>Term</dt> |
| 345 |
<dd> |
| 346 |
<p>Definition</p> |
| 347 |
<p>More text</p> |
| 348 |
</dd> |
| 349 |
<dd> |
| 350 |
<p>Another |
| 351 |
definition</p> |
| 352 |
<p>Even more text</p> |
| 353 |
</dd> |
| 354 |
</dl> |
| 355 |
</details> |
| 356 |
</li> |
| 357 |
</ul> |
| 358 |
''', |
| 359 |
True |
| 360 |
) |
| 361 |
|
| 362 |
def test_details_complex_list(self): |
| 363 |
"""Test details complex list scenario.""" |
| 364 |
|
| 365 |
self.check_markdown( |
| 366 |
''' |
| 367 |
???+ "With details block with loose lists" |
| 368 |
- Parent 1 |
| 369 |
|
| 370 |
- Child 1 |
| 371 |
- Child 2 |
| 372 |
''', |
| 373 |
''' |
| 374 |
<details open="open"> |
| 375 |
<summary>With details block with loose lists</summary> |
| 376 |
<ul> |
| 377 |
<li> |
| 378 |
<p>Parent 1</p> |
| 379 |
<ul> |
| 380 |
<li>Child 1</li> |
| 381 |
<li>Child 2</li> |
| 382 |
</ul> |
| 383 |
</li> |
| 384 |
</ul> |
| 385 |
</details> |
| 386 |
''', |
| 387 |
True |
| 388 |
) |
| 389 |
|
| 390 |
def test_details_complex_list_unindentd_content(self): |
| 391 |
"""Test details complex list scenario with un-indented content.""" |
| 392 |
|
| 393 |
self.check_markdown( |
| 394 |
''' |
| 395 |
???+ "With details block with loose lists" |
| 396 |
- Parent 1 |
| 397 |
|
| 398 |
- Child 1 |
| 399 |
- Child 2 |
| 400 |
- Parent 2 |
| 401 |
''', |
| 402 |
''' |
| 403 |
<details open="open"> |
| 404 |
<summary>With details block with loose lists</summary> |
| 405 |
<ul> |
| 406 |
<li> |
| 407 |
<p>Parent 1</p> |
| 408 |
<ul> |
| 409 |
<li>Child 1</li> |
| 410 |
<li>Child 2</li> |
| 411 |
</ul> |
| 412 |
</li> |
| 413 |
</ul> |
| 414 |
</details> |
| 415 |
<ul> |
| 416 |
<li>Parent 2</li> |
| 417 |
</ul> |
| 418 |
''', |
| 419 |
True |
| 420 |
) |