Code Monkey home page Code Monkey logo

sphinx-code-tabs's Introduction

sphinx code tabs

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)

sphinx-code-tabs's People

Contributors

coldfix avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.