| 1 |
"""Test cases for Blocks (tab).""" |
| 2 |
from ... import util |
| 3 |
from pymdownx.slugs import slugify |
| 4 |
|
| 5 |
|
| 6 |
class TestTabSlugs(util.MdCase): |
| 7 |
"""Test tab slug cases.""" |
| 8 |
|
| 9 |
extension = ['pymdownx.blocks.tab', 'toc'] |
| 10 |
extension_configs = { |
| 11 |
'pymdownx.blocks.tab': {'slugify': slugify(case='lower'), 'alternate_style': True} |
| 12 |
} |
| 13 |
|
| 14 |
MD = r""" |
| 15 |
### Here is some text |
| 16 |
|
| 17 |
/// tab | Here is some text |
| 18 |
content |
| 19 |
/// |
| 20 |
|
| 21 |
/// tab | Here is some text |
| 22 |
content |
| 23 |
/// |
| 24 |
""" |
| 25 |
|
| 26 |
def test_tab_slugs(self): |
| 27 |
"""Test tab slugs.""" |
| 28 |
|
| 29 |
self.check_markdown( |
| 30 |
self.MD, |
| 31 |
''' |
| 32 |
<h3 id="here-is-some-text">Here is some text</h3> |
| 33 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:2"><input checked="checked" id="here-is-some-text_1" name="__tabbed_1" type="radio" /><input id="here-is-some-text_2" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="here-is-some-text_1">Here is some text</label><label for="here-is-some-text_2">Here is some text</label></div> |
| 34 |
<div class="tabbed-content"> |
| 35 |
<div class="tabbed-block"> |
| 36 |
<p>content</p> |
| 37 |
</div> |
| 38 |
<div class="tabbed-block"> |
| 39 |
<p>content</p> |
| 40 |
</div> |
| 41 |
</div> |
| 42 |
</div> |
| 43 |
''', # noqa: E501 |
| 44 |
True |
| 45 |
) |
| 46 |
|
| 47 |
|
| 48 |
class TestTabSlugsSep(util.MdCase): |
| 49 |
"""Test tab slug separator cases.""" |
| 50 |
|
| 51 |
extension = ['pymdownx.blocks.tab', 'toc'] |
| 52 |
extension_configs = { |
| 53 |
'pymdownx.blocks.tab': { |
| 54 |
'slugify': slugify(case='lower'), |
| 55 |
'separator': '_', |
| 56 |
'alternate_style': True |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
MD = r""" |
| 61 |
### Here is some text |
| 62 |
|
| 63 |
/// tab | Here is some text |
| 64 |
content |
| 65 |
/// |
| 66 |
|
| 67 |
/// tab | Here is some text |
| 68 |
content |
| 69 |
/// |
| 70 |
""" |
| 71 |
|
| 72 |
def test_slug_with_separator(self): |
| 73 |
"""Test tab slugs with separator.""" |
| 74 |
|
| 75 |
self.check_markdown( |
| 76 |
self.MD, |
| 77 |
''' |
| 78 |
<h3 id="here-is-some-text">Here is some text</h3> |
| 79 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:2"><input checked="checked" id="here_is_some_text" name="__tabbed_1" type="radio" /><input id="here_is_some_text_1" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="here_is_some_text">Here is some text</label><label for="here_is_some_text_1">Here is some text</label></div> |
| 80 |
<div class="tabbed-content"> |
| 81 |
<div class="tabbed-block"> |
| 82 |
<p>content</p> |
| 83 |
</div> |
| 84 |
<div class="tabbed-block"> |
| 85 |
<p>content</p> |
| 86 |
</div> |
| 87 |
</div> |
| 88 |
</div> |
| 89 |
''', # noqa: E501 |
| 90 |
True |
| 91 |
) |
| 92 |
|
| 93 |
|
| 94 |
class TestTabSlugsCombineHeader(util.MdCase): |
| 95 |
"""Combine header slug with content tab.""" |
| 96 |
|
| 97 |
extension = ['pymdownx.blocks.tab', 'toc', 'pymdownx.blocks.details'] |
| 98 |
extension_configs = { |
| 99 |
'pymdownx.blocks.tab': { |
| 100 |
'slugify': slugify(case='lower'), |
| 101 |
'combine_header_slug': True, |
| 102 |
'alternate_style': True |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
def test_combine_header_slug(self): |
| 107 |
"""Test that slugs are a combination of the header slug and the tab title.""" |
| 108 |
|
| 109 |
md = R""" |
| 110 |
### Here is some text |
| 111 |
|
| 112 |
/// tab | First Tab |
| 113 |
content |
| 114 |
/// |
| 115 |
|
| 116 |
|
| 117 |
### Another header |
| 118 |
|
| 119 |
/// details | title |
| 120 |
//// tab | Second Tab |
| 121 |
content |
| 122 |
//// |
| 123 |
/// |
| 124 |
""" |
| 125 |
|
| 126 |
self.check_markdown( |
| 127 |
md, |
| 128 |
''' |
| 129 |
<h3 id="here-is-some-text">Here is some text</h3> |
| 130 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="here-is-some-text-first-tab" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="here-is-some-text-first-tab">First Tab</label></div> |
| 131 |
<div class="tabbed-content"> |
| 132 |
<div class="tabbed-block"> |
| 133 |
<p>content</p> |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
</div> |
| 137 |
<h3 id="another-header">Another header</h3> |
| 138 |
<details> |
| 139 |
<summary>title</summary> |
| 140 |
<div class="tabbed-set tabbed-alternate" data-tabs="2:1"><input checked="checked" id="another-header-second-tab" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="another-header-second-tab">Second Tab</label></div> |
| 141 |
<div class="tabbed-content"> |
| 142 |
<div class="tabbed-block"> |
| 143 |
<p>content</p> |
| 144 |
</div> |
| 145 |
</div> |
| 146 |
</div> |
| 147 |
</details> |
| 148 |
''', # noqa: E501 |
| 149 |
True |
| 150 |
) |
| 151 |
|
| 152 |
def test_no_header(self): |
| 153 |
"""Test when there is no header.""" |
| 154 |
|
| 155 |
md = R""" |
| 156 |
/// tab | A Tab |
| 157 |
content |
| 158 |
/// |
| 159 |
""" |
| 160 |
|
| 161 |
self.check_markdown( |
| 162 |
md, |
| 163 |
''' |
| 164 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="a-tab" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="a-tab">A Tab</label></div> |
| 165 |
<div class="tabbed-content"> |
| 166 |
<div class="tabbed-block"> |
| 167 |
<p>content</p> |
| 168 |
</div> |
| 169 |
</div> |
| 170 |
</div> |
| 171 |
''', # noqa: E501 |
| 172 |
True |
| 173 |
) |
| 174 |
|
| 175 |
def test_header_after(self): |
| 176 |
"""Test when header comes after.""" |
| 177 |
|
| 178 |
md = R""" |
| 179 |
/// tab | A Tab |
| 180 |
content |
| 181 |
/// |
| 182 |
|
| 183 |
# Header |
| 184 |
""" |
| 185 |
|
| 186 |
self.check_markdown( |
| 187 |
md, |
| 188 |
''' |
| 189 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:1"><input checked="checked" id="a-tab" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="a-tab">A Tab</label></div> |
| 190 |
<div class="tabbed-content"> |
| 191 |
<div class="tabbed-block"> |
| 192 |
<p>content</p> |
| 193 |
</div> |
| 194 |
</div> |
| 195 |
</div> |
| 196 |
<h1 id="header">Header</h1> |
| 197 |
''', # noqa: E501 |
| 198 |
True |
| 199 |
) |
| 200 |
|
| 201 |
|
| 202 |
class TestBlocksTab(util.MdCase): |
| 203 |
"""Test Blocks tab cases.""" |
| 204 |
|
| 205 |
extension = ['pymdownx.blocks.tab', 'pymdownx.superfences', 'markdown.extensions.def_list', 'pymdownx.details'] |
| 206 |
extension_configs = { |
| 207 |
'pymdownx.blocks.tab': {'alternate_style': True} |
| 208 |
} |
| 209 |
|
| 210 |
def test_tabbed_select(self): |
| 211 |
"""Test selecting a tab.""" |
| 212 |
|
| 213 |
self.check_markdown( |
| 214 |
r''' |
| 215 |
/// tab | Tab 1 |
| 216 |
content |
| 217 |
/// |
| 218 |
|
| 219 |
/// tab | Tab 2 |
| 220 |
select: true |
| 221 |
|
| 222 |
content |
| 223 |
/// |
| 224 |
|
| 225 |
/// tab | Tab 3 |
| 226 |
content |
| 227 |
/// |
| 228 |
''', |
| 229 |
r''' |
| 230 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:3"><input id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input checked="checked" id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab 1</label><label for="__tabbed_1_2">Tab 2</label><label for="__tabbed_1_3">Tab 3</label></div> |
| 231 |
<div class="tabbed-content"> |
| 232 |
<div class="tabbed-block"> |
| 233 |
<p>content</p> |
| 234 |
</div> |
| 235 |
<div class="tabbed-block"> |
| 236 |
<p>content</p> |
| 237 |
</div> |
| 238 |
<div class="tabbed-block"> |
| 239 |
<p>content</p> |
| 240 |
</div> |
| 241 |
</div> |
| 242 |
</div> |
| 243 |
''', # noqa: E501 |
| 244 |
True |
| 245 |
) |
| 246 |
|
| 247 |
def test_tabbed_select_multiple(self): |
| 248 |
"""Test selecting multiple tabs.""" |
| 249 |
|
| 250 |
self.check_markdown( |
| 251 |
r''' |
| 252 |
/// tab | Tab 1 |
| 253 |
content |
| 254 |
/// |
| 255 |
|
| 256 |
/// tab | Tab 2 |
| 257 |
select: true |
| 258 |
|
| 259 |
content |
| 260 |
/// |
| 261 |
|
| 262 |
/// tab | Tab 3 |
| 263 |
select: true |
| 264 |
|
| 265 |
content |
| 266 |
/// |
| 267 |
''', |
| 268 |
r''' |
| 269 |
<div class="tabbed-set tabbed-alternate" data-tabs="1:3"><input id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input checked="checked" id="__tabbed_1_3" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Tab 1</label><label for="__tabbed_1_2">Tab 2</label><label for="__tabbed_1_3">Tab 3</label></div> |
| 270 |
<div class="tabbed-content"> |
| 271 |
<div class="tabbed-block"> |
| 272 |
<p>content</p> |
| 273 |
</div> |
| 274 |
<div class="tabbed-block"> |
| 275 |
<p>content</p> |
| 276 |
</div> |
| 277 |
<div class="tabbed-block"> |
| 278 |
<p>content</p> |
| 279 |
</div> |
| 280 |
</div> |
| 281 |
</div> |
| 282 |
''', # noqa: E501 |
| 283 |
True |
| 284 |
) |
| 285 |
|
| 286 |
def test_required_title(self): |
| 287 |
"""Test that tab is not processed if title is omitted.""" |
| 288 |
|
| 289 |
self.check_markdown( |
| 290 |
R''' |
| 291 |
/// tab |
| 292 |
|
| 293 |
Some *content* |
| 294 |
/// |
| 295 |
''', |
| 296 |
r''' |
| 297 |
<p>/// tab</p> |
| 298 |
<p>Some <em>content</em> |
| 299 |
///</p> |
| 300 |
''', |
| 301 |
True |
| 302 |
) |
| 303 |
|
| 304 |
def test_tabbed(self): |
| 305 |
"""Test tabbed.""" |
| 306 |
|
| 307 |
self.check_markdown( |
| 308 |
R''' |
| 309 |
/// tab | Tab |
| 310 |
Some *content* |
| 311 |
|
| 312 |
And more `content`. |
| 313 |
/// |
| 314 |
|
| 315 |
/// tab | Another Tab |
| 316 |
Some more content. |
| 317 |
|
| 318 |
``` |
| 319 |
code |
| 320 |
``` |
| 321 |
/// |
| 322 |
''', |
| 323 |
r''' |
| 324 |
<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> |
| 325 |
<div class="tabbed-content"> |
| 326 |
<div class="tabbed-block"> |
| 327 |
<p>Some <em>content</em></p> |
| 328 |
<p>And more <code>content</code>.</p> |
| 329 |
</div> |
| 330 |
<div class="tabbed-block"> |
| 331 |
<p>Some more content.</p> |
| 332 |
<div class="highlight"><pre><span></span><code>code |
| 333 |
</code></pre></div> |
| 334 |
</div> |
| 335 |
</div> |
| 336 |
</div> |
| 337 |
''', # noqa: E501 |
| 338 |
True |
| 339 |
) |
| 340 |
|
| 341 |
def test_tabbed_markdown_title(self): |
| 342 |
"""Test tabbed.""" |
| 343 |
|
| 344 |
self.check_markdown( |
| 345 |
R''' |
| 346 |
/// tab | **Tab** |
| 347 |
Some *content* |
| 348 |
|
| 349 |
And more `content`. |
| 350 |
/// |
| 351 |
|
| 352 |
/// tab | _Another Tab_ |
| 353 |
Some more content. |
| 354 |
|
| 355 |
``` |
| 356 |
code |
| 357 |
``` |
| 358 |
/// |
| 359 |
''', |
| 360 |
r''' |
| 361 |
<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"><strong>Tab</strong></label><label for="__tabbed_1_2"><em>Another Tab</em></label></div> |
| 362 |
<div class="tabbed-content"> |
| 363 |
<div class="tabbed-block"> |
| 364 |
<p>Some <em>content</em></p> |
| 365 |
<p>And more <code>content</code>.</p> |
| 366 |
</div> |
| 367 |
<div class="tabbed-block"> |
| 368 |
<p>Some more content.</p> |
| 369 |
<div class="highlight"><pre><span></span><code>code |
| 370 |
</code></pre></div> |
| 371 |
</div> |
| 372 |
</div> |
| 373 |
</div> |
| 374 |
''', # noqa: E501 |
| 375 |
True |
| 376 |
) |
| 377 |
|
| 378 |
def test_tabbed_split(self): |
| 379 |
"""Force a split of tab sets.""" |
| 380 |
|
| 381 |
self.check_markdown( |
| 382 |
R''' |
| 383 |
/// tab | Tab |
| 384 |
Some *content* |
| 385 |
|
| 386 |
And more `content`. |
| 387 |
/// |
| 388 |
|
| 389 |
/// tab | Another Tab |
| 390 |
new: true |
| 391 |
|
| 392 |
Some more content. |
| 393 |
|
| 394 |
``` |
| 395 |
code |
| 396 |
``` |
| 397 |
/// |
| 398 |
''', |
| 399 |
r''' |
| 400 |
<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> |
| 401 |
<div class="tabbed-content"> |
| 402 |
<div class="tabbed-block"> |
| 403 |
<p>Some <em>content</em></p> |
| 404 |
<p>And more <code>content</code>.</p> |
| 405 |
</div> |
| 406 |
</div> |
| 407 |
</div> |
| 408 |
<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">Another Tab</label></div> |
| 409 |
<div class="tabbed-content"> |
| 410 |
<div class="tabbed-block"> |
| 411 |
<p>Some more content.</p> |
| 412 |
<div class="highlight"><pre><span></span><code>code |
| 413 |
</code></pre></div> |
| 414 |
</div> |
| 415 |
</div> |
| 416 |
</div> |
| 417 |
''', # noqa: E501 |
| 418 |
True |
| 419 |
) |
| 420 |
|
| 421 |
def test_empty_title(self): |
| 422 |
"""Force a split of tab sets.""" |
| 423 |
|
| 424 |
self.check_markdown( |
| 425 |
R''' |
| 426 |
/// tab | |
| 427 |
Content |
| 428 |
/// |
| 429 |
''', |
| 430 |
r''' |
| 431 |
<p>/// tab | |
| 432 |
Content |
| 433 |
///</p> |
| 434 |
''', |
| 435 |
True |
| 436 |
) |