Skip to main content

Sphinx extension for adding alternative code-blocks as selectable tabs

Project description

Latest Version License: Unlicense Documentation

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.

Screenshot (usernames were changed)

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!):

  • prerender navbar, and CSS “hidden” classes, so that the layout doesn’t change during page reload

  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

helveg--sphinx-code-tabs-0.2.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

helveg_sphinx_code_tabs-0.2.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file helveg--sphinx-code-tabs-0.2.0.tar.gz.

File metadata

File hashes

Hashes for helveg--sphinx-code-tabs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 de4a6ec9f5dc1c79e04c1ed9a2d612757eca21b36e3e5beeea8dabb9586d3bb3
MD5 08d21c92e5491ec8ea7ca6f7855811b3
BLAKE2b-256 41959d65055388c87f1aaf76f110c49b878cd97d926e413c9eb686f981274228

See more details on using hashes here.

File details

Details for the file helveg_sphinx_code_tabs-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for helveg_sphinx_code_tabs-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba3f025701f83857acc84f3e826007340b1d2f1cdbe1c51bef56e78ab75431c6
MD5 7c30e13d22afad44e61e2f61a8fe8d95
BLAKE2b-256 d9db7f49bef643efed39a93a4e4e38008bc56321694814a25bb7351940b1a969

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page