2020-07-20 20:28:13 +03:00
|
|
|
---
|
|
|
|
template: overrides/main.html
|
|
|
|
---
|
|
|
|
|
|
|
|
# Content tabs
|
|
|
|
|
|
|
|
Sometimes, it's desirable to group alternative content under different tabs,
|
|
|
|
e.g. when describing how to access an API from different languages or
|
2021-05-23 14:30:26 +03:00
|
|
|
environments. Material for MkDocs allows for beautiful and functional tabs,
|
|
|
|
grouping code blocks and other content.
|
2020-07-20 20:28:13 +03:00
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
### Tabbed
|
|
|
|
|
|
|
|
[:octicons-file-code-24: Source][1] · [:octicons-workflow-24: Extension][2]
|
|
|
|
|
|
|
|
The [Tabbed][2] extension, which is part of [Python Markdown Extensions][3],
|
2020-07-23 14:17:50 +03:00
|
|
|
integrates with Material for MkDocs and can be enabled via `mkdocs.yml`:
|
2020-07-20 20:28:13 +03:00
|
|
|
|
|
|
|
``` yaml
|
|
|
|
markdown_extensions:
|
|
|
|
- pymdownx.tabbed
|
|
|
|
```
|
|
|
|
|
2020-07-23 10:29:23 +03:00
|
|
|
[1]: https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/main/extensions/pymdownx/_tabbed.scss
|
2020-07-20 20:28:13 +03:00
|
|
|
[2]: https://facelessuser.github.io/pymdown-extensions/extensions/tabbed/
|
|
|
|
[3]: https://facelessuser.github.io/pymdown-extensions/
|
|
|
|
|
2020-07-21 17:01:22 +03:00
|
|
|
### SuperFences
|
|
|
|
|
2020-07-23 16:34:43 +03:00
|
|
|
The [SuperFences][4] extension, which is also part of [Python Markdown
|
|
|
|
Extensions][3], allows for the __nesting of code and content blocks inside
|
|
|
|
tabs__, and is therefore strongly recommended:
|
2020-07-21 17:01:22 +03:00
|
|
|
|
|
|
|
``` yaml
|
|
|
|
markdown_extensions:
|
|
|
|
- pymdownx.superfences
|
|
|
|
```
|
|
|
|
|
2020-07-23 16:34:43 +03:00
|
|
|
[4]: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/
|
2020-07-21 17:01:22 +03:00
|
|
|
|
2020-07-20 20:28:13 +03:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
### Grouping code blocks
|
|
|
|
|
|
|
|
Code blocks are one of the primary targets to be grouped, and can be considered
|
|
|
|
a special case of content tabs, as tabs with a single code block are always
|
|
|
|
rendered without horizontal spacing.
|
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
```
|
|
|
|
=== "C"
|
|
|
|
|
|
|
|
``` c
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
printf("Hello world!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
=== "C++"
|
|
|
|
|
|
|
|
``` c++
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
std::cout << "Hello world!" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
|
|
|
=== "C"
|
|
|
|
|
|
|
|
``` c
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
printf("Hello world!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
=== "C++"
|
|
|
|
|
|
|
|
``` c++
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
std::cout << "Hello world!" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Grouping other content
|
|
|
|
|
|
|
|
When a content tab contains more than one code block, it is rendered with
|
|
|
|
horizontal spacing. Vertical spacing is never added, but can be achieved
|
|
|
|
by nesting tabs in other blocks.
|
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
```
|
|
|
|
=== "Unordered list"
|
|
|
|
|
2020-07-27 13:05:07 +03:00
|
|
|
* Sed sagittis eleifend rutrum
|
|
|
|
* Donec vitae suscipit est
|
|
|
|
* Nulla tempor lobortis orci
|
2020-07-20 20:28:13 +03:00
|
|
|
|
|
|
|
=== "Ordered list"
|
|
|
|
|
|
|
|
1. Sed sagittis eleifend rutrum
|
|
|
|
2. Donec vitae suscipit est
|
|
|
|
3. Nulla tempor lobortis orci
|
|
|
|
```
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
|
|
|
=== "Unordered list"
|
|
|
|
|
2020-07-27 13:05:07 +03:00
|
|
|
* Sed sagittis eleifend rutrum
|
|
|
|
* Donec vitae suscipit est
|
|
|
|
* Nulla tempor lobortis orci
|
2020-07-20 20:28:13 +03:00
|
|
|
|
|
|
|
=== "Ordered list"
|
|
|
|
|
|
|
|
1. Sed sagittis eleifend rutrum
|
|
|
|
2. Donec vitae suscipit est
|
|
|
|
3. Nulla tempor lobortis orci
|
|
|
|
|
2021-05-23 14:30:26 +03:00
|
|
|
### Linking content tabs
|
|
|
|
|
|
|
|
[:octicons-file-code-24: Source][5] ·
|
|
|
|
:octicons-beaker-24: Experimental ·
|
|
|
|
[:octicons-heart-fill-24:{ .mdx-heart } Insiders only][5]{ .mdx-insiders }
|
|
|
|
|
|
|
|
When _linking_ is enabled, all content tabs on a page will be linked and show
|
|
|
|
the same active tab when the user clicks on a label. Add the following lines
|
|
|
|
to `mkdocs.yml`:
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
theme:
|
|
|
|
features:
|
|
|
|
- content.tabs.link
|
|
|
|
```
|
|
|
|
|
|
|
|
Content tabs are linked based on their label, not offset. This means that all
|
|
|
|
tabs with the same label will be activated when a user clicks a content tab
|
|
|
|
regardless of order inside a container. Furthermore, this feature is fully
|
|
|
|
integrated with [instant loading][6] and persisted across page loads.
|
|
|
|
|
|
|
|
=== "With linking"
|
|
|
|
|
|
|
|
[![With linking][7]][7]
|
|
|
|
|
|
|
|
=== "Without linking"
|
|
|
|
|
|
|
|
[![Without linking][8]][8]
|
|
|
|
|
|
|
|
[5]: ../insiders/index.md
|
|
|
|
[6]: ../setup/setting-up-navigation.md#instant-loading
|
|
|
|
[7]: ../assets/screenshots/content-tabs-link.png
|
|
|
|
[8]: ../assets/screenshots/content-tabs.png
|
|
|
|
|
2020-07-20 20:28:13 +03:00
|
|
|
### Embedded content
|
|
|
|
|
2021-05-23 14:30:26 +03:00
|
|
|
When [SuperFences][9] is enabled, content tabs can contain arbitrary nested
|
2020-07-23 16:34:43 +03:00
|
|
|
content, including further content tabs, and can be nested in other blocks like
|
2021-05-23 14:30:26 +03:00
|
|
|
[admonitions][10], [details][11] or blockquotes:
|
2020-07-20 20:28:13 +03:00
|
|
|
|
2020-07-20 20:34:44 +03:00
|
|
|
_Example_:
|
|
|
|
|
|
|
|
``` markdown
|
2020-07-20 20:38:11 +03:00
|
|
|
!!! example
|
2020-07-20 20:34:44 +03:00
|
|
|
|
|
|
|
=== "Unordered List"
|
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
``` markdown
|
2020-07-27 13:05:07 +03:00
|
|
|
* Sed sagittis eleifend rutrum
|
|
|
|
* Donec vitae suscipit est
|
|
|
|
* Nulla tempor lobortis orci
|
2020-07-20 20:34:44 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
2020-07-27 13:05:07 +03:00
|
|
|
* Sed sagittis eleifend rutrum
|
|
|
|
* Donec vitae suscipit est
|
|
|
|
* Nulla tempor lobortis orci
|
2020-07-20 20:34:44 +03:00
|
|
|
|
|
|
|
=== "Ordered List"
|
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
``` markdown
|
|
|
|
1. Sed sagittis eleifend rutrum
|
|
|
|
2. Donec vitae suscipit est
|
|
|
|
3. Nulla tempor lobortis orci
|
|
|
|
```
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
|
|
|
1. Sed sagittis eleifend rutrum
|
|
|
|
2. Donec vitae suscipit est
|
|
|
|
3. Nulla tempor lobortis orci
|
|
|
|
```
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
2020-07-20 20:38:11 +03:00
|
|
|
!!! example
|
2020-07-20 20:28:13 +03:00
|
|
|
|
2020-07-20 20:34:44 +03:00
|
|
|
=== "Unordered List"
|
2020-07-20 20:28:13 +03:00
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
``` markdown
|
2020-07-27 13:05:07 +03:00
|
|
|
* Sed sagittis eleifend rutrum
|
|
|
|
* Donec vitae suscipit est
|
|
|
|
* Nulla tempor lobortis orci
|
2020-07-20 20:28:13 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
2020-07-27 13:05:07 +03:00
|
|
|
* Sed sagittis eleifend rutrum
|
|
|
|
* Donec vitae suscipit est
|
|
|
|
* Nulla tempor lobortis orci
|
2020-07-20 20:28:13 +03:00
|
|
|
|
2020-07-20 20:34:44 +03:00
|
|
|
=== "Ordered List"
|
2020-07-20 20:28:13 +03:00
|
|
|
|
|
|
|
_Example_:
|
|
|
|
|
|
|
|
``` markdown
|
|
|
|
1. Sed sagittis eleifend rutrum
|
|
|
|
2. Donec vitae suscipit est
|
|
|
|
3. Nulla tempor lobortis orci
|
|
|
|
```
|
|
|
|
|
|
|
|
_Result_:
|
|
|
|
|
|
|
|
1. Sed sagittis eleifend rutrum
|
|
|
|
2. Donec vitae suscipit est
|
|
|
|
3. Nulla tempor lobortis orci
|
|
|
|
|
2021-05-23 14:30:26 +03:00
|
|
|
[9]: #superfences
|
|
|
|
[10]: admonitions.md
|
|
|
|
[11]: admonitions.md#details
|