mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
221 lines
4.5 KiB
Markdown
221 lines
4.5 KiB
Markdown
---
|
|
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
|
|
environments. Material for MkDocs allows for beautiful and functional tabs, grouping code blocks and other content.
|
|
|
|
## 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],
|
|
integrates with Material for MkDocs and can be enabled from `mkdocs.yml`:
|
|
|
|
``` yaml
|
|
markdown_extensions:
|
|
- pymdownx.tabbed
|
|
```
|
|
|
|
[1]: https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/extensions/pymdown/_tabbed.scss
|
|
[2]: https://facelessuser.github.io/pymdown-extensions/extensions/tabbed/
|
|
[3]: https://facelessuser.github.io/pymdown-extensions/
|
|
|
|
### SuperFences
|
|
|
|
[:octicons-file-code-24: Source][4] · [:octicons-workflow-24: Extension][5]
|
|
|
|
The [SuperFences][5] extension, which is also part of [Python Markdown
|
|
Extensions][3], allows for the __nesting of code blocks inside tabs__, and is
|
|
therefore strongly recommended:
|
|
|
|
``` yaml
|
|
markdown_extensions:
|
|
- pymdownx.superfences
|
|
```
|
|
|
|
[4]: https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/base/_typeset.scss
|
|
[5]: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/
|
|
|
|
## 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"
|
|
|
|
- Sed sagittis eleifend rutrum
|
|
- Donec vitae suscipit est
|
|
- Nulla tempor lobortis orci
|
|
|
|
=== "Ordered list"
|
|
|
|
1. Sed sagittis eleifend rutrum
|
|
2. Donec vitae suscipit est
|
|
3. Nulla tempor lobortis orci
|
|
```
|
|
|
|
_Result_:
|
|
|
|
=== "Unordered list"
|
|
|
|
- Sed sagittis eleifend rutrum
|
|
- Donec vitae suscipit est
|
|
- Nulla tempor lobortis orci
|
|
|
|
=== "Ordered list"
|
|
|
|
1. Sed sagittis eleifend rutrum
|
|
2. Donec vitae suscipit est
|
|
3. Nulla tempor lobortis orci
|
|
|
|
### Embedded content
|
|
|
|
Content tabs can contain arbitrary nested content, including further content
|
|
tabs, and can be nested in other blocks like [admonitions][6], [details][7] or
|
|
blockquotes:
|
|
|
|
_Example_:
|
|
|
|
``` markdown
|
|
!!! example
|
|
|
|
=== "Unordered List"
|
|
|
|
_Example_:
|
|
|
|
``` markdown
|
|
- Sed sagittis eleifend rutrum
|
|
- Donec vitae suscipit est
|
|
- Nulla tempor lobortis orci
|
|
```
|
|
|
|
_Result_:
|
|
|
|
- Sed sagittis eleifend rutrum
|
|
- Donec vitae suscipit est
|
|
- Nulla tempor lobortis orci
|
|
|
|
=== "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_:
|
|
|
|
!!! example
|
|
|
|
=== "Unordered List"
|
|
|
|
_Example_:
|
|
|
|
``` markdown
|
|
- Sed sagittis eleifend rutrum
|
|
- Donec vitae suscipit est
|
|
- Nulla tempor lobortis orci
|
|
```
|
|
|
|
_Result_:
|
|
|
|
- Sed sagittis eleifend rutrum
|
|
- Donec vitae suscipit est
|
|
- Nulla tempor lobortis orci
|
|
|
|
=== "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
|
|
|
|
[6]: admonitions.md
|
|
[7]: admonitions.md#details
|