Sphinx extension for adding alternative code-blocks as selectable tabs
Project description
This is a Sphinx extension that adds a tabs directive for creating a tabbed widget, allowing the user to switch between them. The individual tabs can be code blocks or general content.
This can be used to e.g. show a snippet in multiple languages, display instructions for alternative platforms, or switch between code and output.
Installation
pip install sphinx_code_tabs
To enable the extension in sphinx, simply add the package name in your conf.py to the list of extensions:
extensions = [
...
'sphinx_code_tabs',
]
Usage
By enabling the extension you get access to the tabs directive that declares a notebook of code block alternatives.
The individual tabs are created with the tab or code-tab directives. A tab can contain arbitrary restructuredText, while a code-tab acts like a code-block and accepts all corresponding arguments. Both types of tabs can appear in the same notebook.
The :selected: option allows to switch to a specified tab at start. By default, the first tab is used.
For example, this is the source of above example:
.. tabs::
.. code-tab:: bash
echo "Hello, *World*!"
.. code-tab:: c
:caption: C/C++
:emphasize-lines: 2
#include <stdio.h>
int main() { printf("Hello, *World*!\n"); }
.. code-tab:: python
print("Hello, *World*!")
.. tab:: Output
:selected:
Hello, *World*!
Grouped tabs
The tabs directive takes an optional argument that identifies its tab group. Within a given tab group, all notebooks will automatically be switched to the same tab number if the tab is switched in one member of the group. It is your responsibility to make sure that each member of the group has the same number and ordering of tabs. Example:
Source:
.. tabs:: lang
.. code-tab:: bash
echo "Hello, group!"
.. code-tab:: python
print("Hello, group!")
.. tabs:: lang
.. code-tab:: bash
echo "Goodbye, group!"
.. code-tab:: python
print("Goodbye, group!")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sphinx_code_tabs-0.5.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a1084ce50693665255aa95a08ad42ccffd5b8e4f8533f4797f086968c4300c8 |
|
MD5 | 9dc21cb68926b36b7b5d9baa7573c0b9 |
|
BLAKE2b-256 | 60bef09f3f23c5937c9415ac6c65d555acf18c8e4c1b22ce709ae06e0e4d42ca |