Sphinx Toggle Button
Sphinx Toggle Button is a Sphinx extension that enables users to add toggle functionality to documentation, allowing them to collapse or expand sections of content and admonitions. The library is actively maintained, with frequent patch releases addressing fixes and minor releases introducing new features. The current version is 0.4.5.
Warnings
- breaking The v0.3.0 and v0.3.2 releases introduced significant visual changes to the toggle buttons and icons. Custom CSS styling targeting older versions (pre-0.3.0) may need adjustment, as the design and layout of the toggle elements were overhauled.
- gotcha By default, `sphinx-togglebutton` applies toggle functionality to elements matching `.toggle` or `.admonition.dropdown` CSS selectors. If you wish to apply toggles to other custom elements or classes, you must explicitly configure the `togglebutton_selector` in `conf.py`.
- gotcha When a Sphinx documentation page containing toggle buttons is printed, all toggle-able content is opened by default. This might not be the desired behavior for all use cases.
Install
-
pip install sphinx-togglebutton
Imports
- Extension Configuration
extensions = ['sphinx_togglebutton'] # in conf.py
Quickstart
# conf.py
extensions = [
'sphinx_togglebutton',
# ... other extensions
]
# example.rst or example.md
.. note:: Click to toggle
:class: dropdown
This content is initially hidden and can be toggled by clicking the admonition title.
.. toggle:: Show/Hide Arbitrary Content
This entire block of content, including paragraphs and other directives,
will be hidden behind a toggle button.
- Item 1
- Item 2