@@ -5,32 +5,32 @@ sphinx-togglebutton
5
5
A small sphinx extension to make it possible to add a "toggle button" to
6
6
sections of your page.
7
7
8
- For example, click the "+" button to the right:
8
+ .. admonition :: For example, click the "+" button to the right:
9
+ :class: dropdown
9
10
10
- .. toggle ::
11
-
12
- .. note :: Here's a toggled admonition
13
-
14
- It was created with this code:
11
+ Here's a toggled note! You can put all kinds of stuff in here!
15
12
16
- .. code-block :: rst
13
+ You can also add a toggle button to arbitrary chunks of content.
14
+ For example, click the toggle button to the right just below.
17
15
18
- .. toggle::
16
+ .. toggle ::
19
17
20
- .. note:: Here's a toggled admonition
18
+ .. admonition :: Wow!
19
+ :class: tip
21
20
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:
21
+ It's a code block!
24
22
25
- .. toggle :: Toggle to see what's inside
23
+ .. code-block :: python
26
24
27
- It's a code block!
25
+ a = " wow, very python "
28
26
29
- .. code-block :: python
27
+ See :ref: ` usage ` for more information.
30
28
31
- a = " wow, very python"
32
- print (" this code should be toggle-able!" )
29
+ .. caution ::
33
30
31
+ ``sphinx-togglebutton `` is designed for the
32
+ `sphinx-book-theme <https://sphinx-book-theme.readthedocs.io/ >`_. It should work
33
+ properly on other themes, but if you notice any CSS bugs, please open an issue!
34
34
35
35
Installation
36
36
============
@@ -41,12 +41,8 @@ You can install `sphinx-togglebutton` with `pip`:
41
41
42
42
pip install sphinx-togglebutton
43
43
44
-
45
- Usage
46
- =====
47
-
48
- In your ``conf.py `` configuration file, add ``sphinx_togglebutton ``
49
- to your extensions list.
44
+ Then, activate it in your ``sphinx `` build by adding it to your ``conf.py `` configuration
45
+ file, like so:
50
46
51
47
E.g.:
52
48
@@ -58,110 +54,113 @@ E.g.:
58
54
...
59
55
]
60
56
57
+ See :ref: `usage ` for information about how to use ``sphinx-togglebutton ``.
61
58
62
- The toggle directive
63
- --------------------
59
+ .. _usage :
64
60
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:
61
+ Usage
62
+ =====
67
63
68
- .. code-block :: rst
64
+ There are two main ways to use `` sphinx-togglebutton ``:
69
65
70
- .. toggle::
66
+ * Create dropdown admonitions with the ``dropdown `` class
67
+ * Make arbitrary chunks of content "toggle-able" with the ``toggle:: `` directive
71
68
72
- Here is my toggle-able content!
69
+ .. _ dropdown-admonitions :
73
70
74
- The code above results in:
71
+ Dropdown admonitions by adding classes
72
+ --------------------------------------
75
73
76
- .. toggle ::
74
+ Making dropdown admonitions allows you to insert extra information in your document
75
+ without forcing the user to see that content. For example:
77
76
78
- Here is my toggle-able content!
77
+ .. admonition :: What could be inside this warning?
78
+ :class: warning, dropdown
79
79
80
- You can also add titles to your toggle-able content:
80
+ A whale of a joke!
81
81
82
- .. code-block :: rst
82
+ .. image :: https://media.giphy.com/media/FaKV1cVKlVRxC/giphy.gif
83
83
84
- .. toggle:: My title
84
+ (sorry)
85
85
86
- Here is my toggle-able content!
86
+ Create a dropdown admonition by adding the ``dropdown `` class to an admonition directive.
87
+ For example, like so:
87
88
88
- Which results in:
89
+ .. code-block :: rst
89
90
91
+ .. note::
92
+ :class: dropdown
90
93
91
- .. toggle :: My title
94
+ My note
92
95
93
- Here is my toggle-able content!
94
-
95
- To show the toggle-able content by default, use the ``:show: `` flag.
96
+ Note that you can use a custom admonition title and apply the style of a "built-in"
97
+ admonition (e.g., ``note ``, ``warning ``, etc) with the ``admonition:: `` directive:
96
98
97
99
.. code-block :: rst
98
100
99
- .. toggle::
100
- :show:
101
-
102
- Here is my toggle-able content!
103
-
104
- It results in the following:
105
-
106
- .. toggle ::
107
- :show:
101
+ .. admonition:: Here's my title
102
+ :class: dropdown, warning
108
103
109
- Here is my toggle-able content!
104
+ My note
110
105
106
+ Creates:
111
107
112
- Toggling content by adding classes
113
- ----------------------------------
108
+ .. admonition :: Here's my title
109
+ :class: dropdown, warning
114
110
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.
111
+ My custom admonition!
118
112
119
- For example, this code would create a toggle-able "note" admonition:
113
+ To show the content by default, add a `` toggle-shown `` class as well.
120
114
121
115
.. code-block :: rst
122
116
123
117
.. note::
124
- :class: toggle
118
+ :class: dropdown, toggle-shown
125
119
126
120
This is my note.
127
121
128
- Here's how it looks :
122
+ This will generate the following block :
129
123
130
124
.. note ::
131
- :class: toggle
125
+ :class: dropdown, toggle-shown
132
126
133
127
This is my note.
134
128
135
- Clicking on the toggle button will toggle the item's visibility.
129
+ .. _ toggle-directive :
136
130
131
+ Toggle any content with the toggle directive
132
+ --------------------------------------------
137
133
138
- To show the content by default, add a ``toggle-shown `` class as well.
134
+ To add toggle-able content, use the **toggle directive **. This directive
135
+ will wrap its content in a toggle-able container. You can call it like so:
139
136
140
137
.. code-block :: rst
141
138
142
- .. note::
143
- :class: toggle, toggle-shown
139
+ .. toggle::
144
140
145
- This is my note.
141
+ Here is my toggle-able content!
146
142
147
- This will generate the following block :
143
+ The code above results in :
148
144
149
- .. note ::
150
- :class: toggle, toggle-shown
145
+ .. toggle ::
151
146
152
- This is my note.
147
+ Here is my toggle-able content!
153
148
154
- Here's how they look right after one another:
149
+ To show the toggle-able content by default, use the `` :show: `` flag.
155
150
156
- .. note ::
157
- :class: toggle
151
+ .. code-block :: rst
158
152
159
- This is my note.
153
+ .. toggle::
154
+ :show:
160
155
161
- .. note ::
162
- :class: toggle
156
+ Here is my toggle-able content!
163
157
164
- This is my second.
158
+ It results in the following:
159
+
160
+ .. toggle ::
161
+ :show:
162
+
163
+ Here is my toggle-able content!
165
164
166
165
167
166
Configuration
@@ -170,42 +169,38 @@ Configuration
170
169
Below are a few configuration points for ``sphinx-togglebutton ``.
171
170
172
171
173
- Control the selector text used to make elements toggle-able
174
- -----------------------------------------------------------
172
+ Control the togglebutton hover text
173
+ -----------------------------------
175
174
176
- By default, ``sphinx-togglebutton `` selects any items that have the class ``.toggle ``
177
- and adds a toggle-button to them. If you'd like to change this class, for example to
178
- select a different kind of HTML element, you may configure this field manually like so
175
+ You can control the "hint" text that is displayed next to togglebuttons when
176
+ their content is collapsed. To do so, use the following configuration variable
179
177
in your ``conf.py `` file:
180
178
181
179
.. code-block :: python
182
180
183
- togglebutton_selector = " your-selector "
181
+ togglebutton_hint = " My text "
184
182
185
- For example, if you wanted to add toggle-buttons to all HTML elements that had a
186
- ``toggle-this-item `` class, in *addition * to the default class of ``toggle ``,
187
- you could do so with the following configuration:
183
+ Reference
184
+ =========
188
185
189
- .. code-block :: python
186
+ This is a simple reference section to double-check styling etc.
190
187
191
- togglebutton_selector = " .toggle, .toggle-this-item "
188
+ Here's how they look right after one another:
192
189
190
+ .. note ::
191
+ :class: toggle
193
192
194
- This is what has been done for the toggle-able section below:
193
+ This is my note.
195
194
196
195
.. note ::
197
- :class: toggle-this-item
198
-
199
- A toggled note with a custom class to trigger toggling.
196
+ :class: toggle
200
197
198
+ This is my second.
201
199
202
- Control the togglebutton hover text
203
- -----------------------------------
200
+ .. toggle ::
204
201
205
- You can control the "hint" text that is displayed next to togglebuttons when
206
- their content is collapsed. To do so, use the following configuration variable
207
- in your ``conf.py `` file:
202
+ This is my first.
208
203
209
- .. code-block :: python
204
+ .. toggle ::
210
205
211
- togglebutton_hint = " My text "
206
+ This is my second.
0 commit comments