@@ -7,23 +7,26 @@ sections of your page.
77
88For example, click the "+" button to the right:
99
10- .. note :: Here's a toggled admonition
11- :class: toggle
10+ .. toggle ::
11+
12+ .. note :: Here's a toggled admonition
1213
1314It was created with this code:
1415
15- .. code :: rst
16+ .. code-block :: rst
1617
17- .. note:: Here's a toggled admonition
18- :class: toggle
18+ .. toggle::
19+
20+ .. note:: Here's a toggled admonition
1921
20- (admonition body here)
22+ You can also add a title to your toggled block. The title will show up,
23+ and the toggle button will change the block's content. For example:
2124
22- And here's a code block:
25+ .. toggle :: Toggle to see what's inside
2326
24- .. container :: toggle
27+ It's a code block!
2528
26- .. code :: python
29+ .. code-block :: python
2730
2831 a = " wow, very python"
2932 print (" this code should be toggle-able!" )
@@ -34,7 +37,7 @@ Installation
3437
3538You can install `sphinx-togglebutton ` with `pip `:
3639
37- .. code :: bash
40+ .. code-block :: bash
3841
3942 pip install sphinx-togglebutton
4043
@@ -47,20 +50,75 @@ to your extensions list.
4750
4851E.g.:
4952
50- .. code :: python
53+ .. code-block :: python
5154
5255 extensions = [
5356 ...
5457 ' sphinx_togglebutton'
5558 ...
5659 ]
5760
58- Now, whenever you wish for an admonition to be toggle-able, add the
59- ``:class: toggle `` parameter to the admonition directive that you use.
61+
62+ The toggle directive
63+ --------------------
64+
65+ To add toggle-able content, use the **toggle directive **. This directive
66+ will wrap its content in a toggle-able container. You can call it like so:
67+
68+ .. code-block :: rst
69+
70+ .. toggle::
71+
72+ Here is my toggle-able content!
73+
74+ The code above results in:
75+
76+ .. toggle ::
77+
78+ Here is my toggle-able content!
79+
80+ You can also add titles to your toggle-able content:
81+
82+ .. code-block :: rst
83+
84+ .. toggle:: My title
85+
86+ Here is my toggle-able content!
87+
88+ Which results in:
89+
90+
91+ .. toggle :: My title
92+
93+ Here is my toggle-able content!
94+
95+ To show the toggle-able content by default, use the ``:show: `` flag.
96+
97+ .. code-block :: rst
98+
99+ .. toggle::
100+ :show:
101+
102+ Here is my toggle-able content!
103+
104+ It results in the following:
105+
106+ .. toggle ::
107+ :show:
108+
109+ Here is my toggle-able content!
110+
111+
112+ Toggling content by adding classes
113+ ----------------------------------
114+
115+ You can also make elements toggle-able by adding the ``toggle `` class to
116+ them. This can be done with admonitions and containers with the
117+ ``:class: my, classes `` keyword.
60118
61119For example, this code would create a toggle-able "note" admonition:
62120
63- .. code :: rst
121+ .. code-block :: rst
64122
65123 .. note::
66124 :class: toggle
@@ -77,14 +135,9 @@ Here's how it looks:
77135Clicking on the toggle button will toggle the item's visibility.
78136
79137
80- Show content by default
81- -----------------------
138+ To show the content by default, add a ``toggle-shown `` class as well.
82139
83- By default, all items with toggle buttons added to them will be hidden by
84- default. You may also **show the content by default **. To do so, add the
85- ``toggle `` class *as well as * a ``toggle-shown `` class, like so:
86-
87- .. code :: rst
140+ .. code-block :: rst
88141
89142 .. note::
90143 :class: toggle, toggle-shown
@@ -98,28 +151,6 @@ This will generate the following block:
98151
99152 This is my note.
100153
101- Toggle any container of content
102- -------------------------------
103-
104- You can also use **containers ** to add arbitrary toggle-able code. For example,
105- here's a container with an image inside:
106-
107- .. container :: toggle
108-
109- .. admonition :: Look at that, an image!
110-
111- .. image :: https://media.giphy.com/media/mW05nwEyXLP0Y/giphy.gif
112-
113- It was generated with this code:
114-
115- .. code :: rst
116-
117- .. container:: toggle
118-
119- .. admonition:: Look at that, an image!
120-
121- .. image:: https://media.giphy.com/media/mW05nwEyXLP0Y/giphy.gif
122-
123154Here's how they look right after one another:
124155
125156.. note ::
@@ -132,28 +163,14 @@ Here's how they look right after one another:
132163
133164 This is my second.
134165
135- Customize the selector words used to toggle content
136- ---------------------------------------------------
137-
138- ``sphinx-togglebutton `` adds a toggle button to elements that are selected
139- by a CSS selection query. By default, this is ``.toggle ``. You can customize
140- the query that is used with the following Sphinx parameter (in ``conf.py ``):
141166
142- .. code-block :: python
143-
144- togglebutton_selector = " <your-selector>
167+ Configuration
168+ =============
145169
146- For example, the documentation with this site uses the following configuration
147- value:
170+ You can control the "hint" text that is displayed next to togglebuttons when
171+ their content is collapsed. To do so, use the following configuration variable
172+ in your ``conf.py `` file:
148173
149174.. code-block :: python
150175
151- togglebutton_selector = " .toggle, .secondtoggle"
152-
153- This means that any element with either of these classes will have toggle
154- buttons added to them.
155-
156- .. note ::
157- :class: secondtoggle
158-
159- A note with a ``.secondtoggle `` class.
176+ togglebutton_hint = " My text"
0 commit comments