Skip to main content

Toggle page content and collapse admonitions in Sphinx.

Project description

sphinx-togglebutton

A small sphinx extension to make it possible to add a "toggle button" to sections of your page. This allows you to:

  • Collapse Sphinx admonitions (notes, warnings, etc) so that their content is hidden until users click a toggle button.
  • Collapse arbitrary chunks of content on your page with a collapse directive.

Demonstration of Sphinx Togglebutton

Installation

You can install sphinx-togglebutton with pip:

pip install sphinx-togglebutton

Usage

In your conf.py configuration file, add sphinx_togglebutton to your extensions list.

E.g.:

extensions = [
    ...
    'sphinx_togglebutton'
    ...
]

Now, whenever you wish for an admonition to be toggle-able, add the :class: dropdown parameter to the admonition directive that you use.

For example, this code would create a toggle-able "note" admonition that starts hidden:

.. note::
    :class: dropdown

    This is my note.

Clicking on the toggle button will toggle the item's visibility.

You may also show the content by default. To do so, add the dropdown class as well as a toggle-shown class, like so:

.. note::
    :class: dropdown, toggle-shown

    This is my note.

You can also use containers to add arbitrary toggle-able code. For example, here's a container with an image inside:

.. container:: toggle, toggle-hidden

    .. admonition:: Look at that, an image!

        .. image:: https://media.giphy.com/media/mW05nwEyXLP0Y/giphy.gif

Internationalization (i18n)

The texts Click to hide and Click to show used in the toggle buttons are internationalized by using the set language from Sphinx's configuration.

Supported languages are English (default), Chinese (Simplified), Chinese (Traditional), Hindi, Spanish, French, Arabic, Bengali, Russian, Portuguese, Indonesian, Japanese, German, Korean, Turkish, Vietnamese, Tamil, Italian, Thai, Dutch, Greek, Polish, Ukrainian, Persian, Malay, Swahili, Romanian, Czech, Hungarian, Hebrew, Swedish, and Norwegian.

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

sphinx_togglebutton-0.4.4.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_togglebutton-0.4.4-py3-none-any.whl (44.9 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_togglebutton-0.4.4.tar.gz.

File metadata

  • Download URL: sphinx_togglebutton-0.4.4.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sphinx_togglebutton-0.4.4.tar.gz
Algorithm Hash digest
SHA256 04c332692fd5f5363ad02a001e693369767d6c1f0e58279770a2aeb571b472a1
MD5 86fe9ac8d8ff13b9a5dfdc6b5a58630f
BLAKE2b-256 896b19def5241b45a7ae90fd91052bb91fa7b8fbcc0606a0cf65ac4ea70fb93b

See more details on using hashes here.

File details

Details for the file sphinx_togglebutton-0.4.4-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_togglebutton-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 820658cd4c4c34c2ee7a21105e638b2f65a9e1d43ee991090715eb7fd9683cdf
MD5 58310a9225444669d8cbec3268117ecf
BLAKE2b-256 facb9f6ceb4308ebfe5f393a271ee6206e17883edee0662a9b5c1a371878064b

See more details on using hashes here.

Supported by

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