| 1 |
"""Test cases for Blocks (legacy tab).""" |
| 2 |
from ... import util |
| 3 |
from pymdownx.slugs import slugify |
| 4 |
|
| 5 |
|
| 6 |
class TestLegacyTabSlugs(util.MdCase): |
| 7 |
"""Test legacy tab slug cases.""" |
| 8 |
|
| 9 |
extension = ['pymdownx.blocks.tab', 'toc'] |
| 10 |
extension_configs = { |
| 11 |
'pymdownx.blocks.tab': {'slugify': slugify(case='lower')} |
| 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" data-tabs="1:2"><input checked="checked" id="here-is-some-text_1" name="__tabbed_1" type="radio" /><label for="here-is-some-text_1">Here is some text</label><div class="tabbed-content"> |
| 34 |
<p>content</p> |
| 35 |
</div> |
| 36 |
<input id="here-is-some-text_2" name="__tabbed_1" type="radio" /><label for="here-is-some-text_2">Here is some text</label><div class="tabbed-content"> |
| 37 |
<p>content</p> |
| 38 |
</div> |
| 39 |
</div> |
| 40 |
''', # noqa: E501 |
| 41 |
True |
| 42 |
) |
| 43 |
|
| 44 |
|
| 45 |
class TestLegacyTabSlugsSep(util.MdCase): |
| 46 |
"""Test legacy tab slug separator cases.""" |
| 47 |
|
| 48 |
extension = ['pymdownx.blocks.tab', 'toc'] |
| 49 |
extension_configs = { |
| 50 |
'pymdownx.blocks.tab': {'slugify': slugify(case='lower'), 'separator': '_'} |
| 51 |
} |
| 52 |
|
| 53 |
MD = r""" |
| 54 |
### Here is some text |
| 55 |
|
| 56 |
/// tab | Here is some text |
| 57 |
content |
| 58 |
/// |
| 59 |
|
| 60 |
/// tab | Here is some text |
| 61 |
content |
| 62 |
/// |
| 63 |
""" |
| 64 |
|
| 65 |
def test_slug_with_separator(self): |
| 66 |
"""Test tab slugs with separator.""" |
| 67 |
|
| 68 |
self.check_markdown( |
| 69 |
self.MD, |
| 70 |
''' |
| 71 |
<h3 id="here-is-some-text">Here is some text</h3> |
| 72 |
<div class="tabbed-set" data-tabs="1:2"><input checked="checked" id="here_is_some_text" name="__tabbed_1" type="radio" /><label for="here_is_some_text">Here is some text</label><div class="tabbed-content"> |
| 73 |
<p>content</p> |
| 74 |
</div> |
| 75 |
<input id="here_is_some_text_1" name="__tabbed_1" type="radio" /><label for="here_is_some_text_1">Here is some text</label><div class="tabbed-content"> |
| 76 |
<p>content</p> |
| 77 |
</div> |
| 78 |
</div> |
| 79 |
''', # noqa: E501 |
| 80 |
True |
| 81 |
) |
| 82 |
|
| 83 |
|
| 84 |
class TestBlocksLegacyTab(util.MdCase): |
| 85 |
"""Test Blocks legacy tab cases.""" |
| 86 |
|
| 87 |
extension = ['pymdownx.blocks.tab', 'pymdownx.superfences', 'markdown.extensions.def_list', 'pymdownx.details'] |
| 88 |
|
| 89 |
def test_tabbed_select(self): |
| 90 |
"""Test selecting a tab.""" |
| 91 |
|
| 92 |
self.check_markdown( |
| 93 |
r''' |
| 94 |
/// tab | Tab 1 |
| 95 |
content |
| 96 |
/// |
| 97 |
|
| 98 |
/// tab | Tab 2 |
| 99 |
select: true |
| 100 |
|
| 101 |
content |
| 102 |
/// |
| 103 |
|
| 104 |
/// tab | Tab 3 |
| 105 |
|
| 106 |
content |
| 107 |
/// |
| 108 |
''', |
| 109 |
r''' |
| 110 |
<div class="tabbed-set" data-tabs="1:3"><input id="__tabbed_1_1" name="__tabbed_1" type="radio" /><label for="__tabbed_1_1">Tab 1</label><div class="tabbed-content"> |
| 111 |
<p>content</p> |
| 112 |
</div> |
| 113 |
<input checked="checked" id="__tabbed_1_2" name="__tabbed_1" type="radio" /><label for="__tabbed_1_2">Tab 2</label><div class="tabbed-content"> |
| 114 |
<p>content</p> |
| 115 |
</div> |
| 116 |
<input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><label for="__tabbed_1_3">Tab 3</label><div class="tabbed-content"> |
| 117 |
<p>content</p> |
| 118 |
</div> |
| 119 |
</div> |
| 120 |
''', # noqa: E501 |
| 121 |
True |
| 122 |
) |
| 123 |
|
| 124 |
def test_tabbed_select_multiple(self): |
| 125 |
"""Test selecting multiple tabs.""" |
| 126 |
|
| 127 |
self.check_markdown( |
| 128 |
r''' |
| 129 |
/// tab | Tab 1 |
| 130 |
content |
| 131 |
/// |
| 132 |
|
| 133 |
/// tab | Tab 2 |
| 134 |
select: true |
| 135 |
|
| 136 |
content |
| 137 |
/// |
| 138 |
|
| 139 |
/// tab | Tab 3 |
| 140 |
select: true |
| 141 |
|
| 142 |
content |
| 143 |
/// |
| 144 |
''', |
| 145 |
r''' |
| 146 |
<div class="tabbed-set" data-tabs="1:3"><input id="__tabbed_1_1" name="__tabbed_1" type="radio" /><label for="__tabbed_1_1">Tab 1</label><div class="tabbed-content"> |
| 147 |
<p>content</p> |
| 148 |
</div> |
| 149 |
<input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><label for="__tabbed_1_2">Tab 2</label><div class="tabbed-content"> |
| 150 |
<p>content</p> |
| 151 |
</div> |
| 152 |
<input checked="checked" id="__tabbed_1_3" name="__tabbed_1" type="radio" /><label for="__tabbed_1_3">Tab 3</label><div class="tabbed-content"> |
| 153 |
<p>content</p> |
| 154 |
</div> |
| 155 |
</div> |
| 156 |
''', # noqa: E501 |
| 157 |
True |
| 158 |
) |
| 159 |
|
| 160 |
def test_required_title(self): |
| 161 |
"""Test that tab is not processed if title is omitted.""" |
| 162 |
|
| 163 |
self.check_markdown( |
| 164 |
R''' |
| 165 |
/// tab |
| 166 |
Some *content* |
| 167 |
/// |
| 168 |
''', |
| 169 |
r''' |
| 170 |
<p>/// tab |
| 171 |
Some <em>content</em> |
| 172 |
///</p> |
| 173 |
''', |
| 174 |
True |
| 175 |
) |
| 176 |
|
| 177 |
def test_tabbed(self): |
| 178 |
"""Test tabbed.""" |
| 179 |
|
| 180 |
self.check_markdown( |
| 181 |
R''' |
| 182 |
/// tab | Tab |
| 183 |
Some *content* |
| 184 |
|
| 185 |
And more `content`. |
| 186 |
/// |
| 187 |
|
| 188 |
/// tab | Another Tab |
| 189 |
Some more content. |
| 190 |
|
| 191 |
``` |
| 192 |
code |
| 193 |
``` |
| 194 |
/// |
| 195 |
''', |
| 196 |
r''' |
| 197 |
<div class="tabbed-set" data-tabs="1:2"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><label for="__tabbed_1_1">Tab</label><div class="tabbed-content"> |
| 198 |
<p>Some <em>content</em></p> |
| 199 |
<p>And more <code>content</code>.</p> |
| 200 |
</div> |
| 201 |
<input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><label for="__tabbed_1_2">Another Tab</label><div class="tabbed-content"> |
| 202 |
<p>Some more content.</p> |
| 203 |
<div class="highlight"><pre><span></span><code>code |
| 204 |
</code></pre></div> |
| 205 |
</div> |
| 206 |
</div> |
| 207 |
''', # noqa: E501 |
| 208 |
True |
| 209 |
) |
| 210 |
|
| 211 |
def test_tabbed_markdown_title(self): |
| 212 |
"""Test tabbed.""" |
| 213 |
|
| 214 |
self.check_markdown( |
| 215 |
R''' |
| 216 |
/// tab | **Tab** |
| 217 |
Some *content* |
| 218 |
|
| 219 |
And more `content`. |
| 220 |
/// |
| 221 |
|
| 222 |
/// tab | _Another Tab_ |
| 223 |
Some more content. |
| 224 |
|
| 225 |
``` |
| 226 |
code |
| 227 |
``` |
| 228 |
/// |
| 229 |
''', |
| 230 |
r''' |
| 231 |
<div class="tabbed-set" data-tabs="1:2"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><label for="__tabbed_1_1"><strong>Tab</strong></label><div class="tabbed-content"> |
| 232 |
<p>Some <em>content</em></p> |
| 233 |
<p>And more <code>content</code>.</p> |
| 234 |
</div> |
| 235 |
<input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><label for="__tabbed_1_2"><em>Another Tab</em></label><div class="tabbed-content"> |
| 236 |
<p>Some more content.</p> |
| 237 |
<div class="highlight"><pre><span></span><code>code |
| 238 |
</code></pre></div> |
| 239 |
</div> |
| 240 |
</div> |
| 241 |
''', # noqa: E501 |
| 242 |
True |
| 243 |
) |
| 244 |
|
| 245 |
def test_tabbed_split(self): |
| 246 |
"""Force a split of tab sets.""" |
| 247 |
|
| 248 |
self.check_markdown( |
| 249 |
R''' |
| 250 |
/// tab | Tab |
| 251 |
Some *content* |
| 252 |
|
| 253 |
And more `content`. |
| 254 |
/// |
| 255 |
|
| 256 |
/// tab | Another Tab |
| 257 |
new: true |
| 258 |
|
| 259 |
Some more content. |
| 260 |
|
| 261 |
``` |
| 262 |
code |
| 263 |
``` |
| 264 |
/// |
| 265 |
''', |
| 266 |
r''' |
| 267 |
<div class="tabbed-set" data-tabs="1:1"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><label for="__tabbed_1_1">Tab</label><div class="tabbed-content"> |
| 268 |
<p>Some <em>content</em></p> |
| 269 |
<p>And more <code>content</code>.</p> |
| 270 |
</div> |
| 271 |
</div> |
| 272 |
<div class="tabbed-set" data-tabs="2:1"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><label for="__tabbed_2_1">Another Tab</label><div class="tabbed-content"> |
| 273 |
<p>Some more content.</p> |
| 274 |
<div class="highlight"><pre><span></span><code>code |
| 275 |
</code></pre></div> |
| 276 |
</div> |
| 277 |
</div> |
| 278 |
''', # noqa: E501 |
| 279 |
True |
| 280 |
) |