Debian Codegraph @

docs/src/markdown/extensions/blocks/plugins/tab.md

raw
1 ---
2 icon: lucide/app-window
3 ---
4 [:octicons-file-code-24:][_tab_block]{: .source-link }
5
6 # Tab
7
8 /// danger | Using `pymdownx.blocks.tab` with `pymdownx.tabbed`
9 The new `pymdownx.blocks.tab` extension is meant to replace `pymdownx.tabbed`, they are not meant to be used together.
10 Their output is identical making it easy to transition by simply swapping out the syntax, but using them both together
11 can cause issues as they both generate the same output and confuse each other.
12
13 If you are switching from `pymdownx.tabbed` to `pymdownx.blocks.tab`, ensure you disable `pymdownx.tabbed` to avoid
14 issues.
15 ///
16
17 ## Overview
18
19 Tab blocks are aimed at replacing the [Tabbed extension](../../tabbed.md). They function identical to Tabbed in every
20 way, even using the same classes, except they use the new generic block syntax.
21
22 By default, the meta-plugin is registered when `pymdownx.blocks` is registered, but if you were customizing which
23 meta-plugins get loaded, you can do so by doing the following:
24
25 ```py3
26 import markdown
27 md = markdown.Markdown(extensions=['pymdownx.blocks.tab'])
28 ```
29
30 ## Usage
31
32 A tab can be defined using the generic block syntax and the name `tab`. Tabs should also specify the tab title in the
33 header. Consecutive tabs will automatically be grouped.
34
35 ```text title="Tabs"
36 /// tab | Tab 1 title
37 Tab 1 content
38 ///
39
40 /// tab | Tab 2 title
41 Tab 2 content
42 ///
43 ```
44
45 /// html | div.result
46
47 //// tab | Tab 1 title
48 Tab 1 content
49 ////
50
51 //// tab | Tab 2 title
52 Tab 2 content
53 ////
54 ///
55
56 If you want to have two tab containers right after each other, you specify a hard break that will force the specified
57 tab to start a brand new tab container.
58
59 ```text title="New Tab Group"
60 /// tab | Tab A title
61 Tab A content
62 ///
63
64 /// tab | Tab B title
65 Tab B content
66 ///
67
68 /// tab | Tab C Title
69 new: true
70
71 Will be part of a separate, new tab group.
72 ///
73 ```
74
75 /// html | div.result
76
77 //// tab | Tab A title
78 Tab A content
79 ////
80
81 //// tab | Tab B title
82 Tab B content
83 ////
84
85 //// tab | Tab C title
86 new: true
87 Will be part of a separate, new tab group.
88 ////
89 ///
90
91 If desired, you can specify a tab to be selected by default with the `select` option.
92
93 ```
94 /// tab | Tab 1 title
95 Tab 1 content
96 ///
97
98 /// tab | Tab 2 title
99 select: True
100
101 Tab 2 should be selected by default.
102 ///
103 ```
104
105 As with all block plugins, you can always add new classes IDs or other attributes via the `attributes` option.
106
107 ```
108 /// tab | Some title
109 attrs: {class: class-name: id: id-name}
110
111 Some content
112 ///
113 ```
114
115 ## Tab IDs
116
117 By default, tabs generate IDs for each tab using the following template `__tabbed_<tab_set_number>_<tab_number>`. If it
118 is desired to implement jumping to a specific tab with more intuitive IDs, it may be preferable to generate IDs from
119 slugs. To do so, two [options](#global-options) are provided: `slugify` and `separator`.
120
121 /// tip
122 Jumping to tabs via IDs may require additional JavaScript to select the targeted tabs.
123 ///
124
125 If `slugify` is given a slug function (you can use any that [ship with Pymdownx Extensions](../../../extras/slugs.md)),
126 the Tabbed extension will generate IDs from the tab titles just like headers. `separator` allows for the specifying of
127 the word separator (`-` is the default).
128
129 If you'd like the slugs to be prefixed with the slug of the parent header, you can enable the `combine_header_slug`
130 option. If you had the following example, normally the header slug would be `header` and the content tab would have the
131 slug `tab`.
132
133 ```
134 # header
135
136 /// tab | tab
137 content
138 ///
139 ```
140
141 With `combine_header_slug` enabled, the header slug would still be `header`, but now the content tab slug would be
142 `header-tab`.
143
144 /// new | New 10.1
145 `combine_header_slug` is new in 10.1
146 ///
147
148 ## Additional Topics
149
150 As Tab shares the same output and functionality as the [Tabbed extension](../../tabbed.md), you can check out the
151 documentation there to learn the following:
152
153 - [How to style the tabs?](../../tabbed.md#styling-with-css)
154 - [How to link tab selection on an entire page?](../../tabbed.md#linked-tabs)
155 - [What is the alternate style and how do I style them?](../../tabbed.md#alternate-style)
156
157 ## Global Options
158
159 Options | Type | Descriptions
160 --------------------- | -------- | ------------
161 `alternate_style` | bool | Use the experimental, alternative style.
162 `slugify` | function | A function to generate slugs from tab titles.
163 `separator` | string | Default word separator when generating slugs.
164 `combine_header_slug` | bool | Combine the parent header slug with the tab content slug.
165
166 ## Per Block Options
167
168 Options | Type | Descriptions
169 ------------ | ---------- | ------------
170 `new` | bool | Force the current tab to start a new tab container.
171 `select` | bool | Force the given tab to be selected in the parent tab container.
172 `attrs` | dictionary | A dictionary that defines attributes for the outer, wrapper element.