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.5.tar.gz (18.1 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.5-py3-none-any.whl (44.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sphinx_togglebutton-0.4.5.tar.gz
  • Upload date:
  • Size: 18.1 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.5.tar.gz
Algorithm Hash digest
SHA256 c870dfbd3bc6e119b50ff9a37a64f8991902269e856728931c7d89877e8d4b3d
MD5 9f2ebd99cc8c2d71f5cc7918ddb75b20
BLAKE2b-256 ccbe169a0b0a8ad9588e8697c85e1d489aaaca7416073c2fc0267c360af5aae9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sphinx_togglebutton-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 74eac6d2426110c3e1e6f989a98e07d7823141a335df1ad8a9d637bdf6a7af62
MD5 b609889ef1d6559a4348f1b835835af3
BLAKE2b-256 d82e3dd55564928c5d61f92827d4b91307dde7911a40fbe0000645d73202eea9

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