Sphinx extension for adding alternative code-blocks as selectable tabs
Project description
This is a Sphinx extension that adds a directive code-tabs that creates a navbar above several alternative code blocks, allowing the user to switch between them.
This can be used to e.g. show a snippet in multiple languages, display instructions for alternative platforms, or (in the future) switch between source 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 code-tabs directive that declares a notebook of code block alternatives.
The individual tabs must be created with the code-tab directive which derives from code-block and accepts all of its arguments:
.. code-tabs::
.. code-tab:: bash
:title: bash
echo "Hello, World!"
.. code-tab:: c
:title: C/C++
:emphasize-lines: 2
#include <stdio.h>
int main() { printf("Hello, world!\n"); }
.. code-tab:: python
:title: python
print("Hello, world!")
Planned changes
This project has just started. Planned features for the next releases (this might initially include backward-incompatible changes!):
add mechanism to group several tab widgets together, so that the selection is kept in sync (which means users interested in a specific language won’t have to change the language on each snippet individually in a longer article)
adopt “caption” attribute rather using our own “title”
reuse “code-block” rather than introducing our own “code-tab” (?)
allow tabs other than code-blocks (maybe)
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.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc03bfcd68c24551938fb0c6fc1c2b2dce0ab6d49d965114ad91d543c2648ff6 |
|
MD5 | d54eb36f538368b9f273807c960a5ffa |
|
BLAKE2b-256 | 02a1ad7695ad87772ebb7b546ce95493a7b89b03e586b10ec7f02104968bbc6d |