1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
# 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.

Installation
============
You can install `sphinx-togglebutton` with `pip`:
```bash
pip install sphinx-togglebutton
```
Usage
=====
In your `conf.py` configuration file, add `sphinx_togglebutton`
to your extensions list.
E.g.:
```python
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:
```rst
.. 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:
```rst
.. 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:
```rst
.. container:: toggle, toggle-hidden
.. admonition:: Look at that, an image!
.. image:: https://media.giphy.com/media/mW05nwEyXLP0Y/giphy.gif
```
|