@@ -5,32 +5,32 @@ sphinx-togglebutton
55A small sphinx extension to make it possible to add a "toggle button" to
66sections of your page.
77
8- For example, click the "+" button to the right:
8+ .. admonition :: For example, click the "+" button to the right:
9+ :class: dropdown
910
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!
1512
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.
1715
18- .. toggle::
16+ .. toggle ::
1917
20- .. note:: Here's a toggled admonition
18+ .. admonition :: Wow!
19+ :class: tip
2120
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!
2422
25- .. toggle :: Toggle to see what's inside
23+ .. code-block :: python
2624
27- It's a code block!
25+ a = " wow, very python "
2826
29- .. code-block :: python
27+ See :ref: ` usage ` for more information.
3028
31- a = " wow, very python"
32- print (" this code should be toggle-able!" )
29+ .. caution ::
3330
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!
3434
3535Installation
3636============
@@ -41,12 +41,8 @@ You can install `sphinx-togglebutton` with `pip`:
4141
4242 pip install sphinx-togglebutton
4343
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:
5046
5147E.g.:
5248
@@ -58,110 +54,113 @@ E.g.:
5854 ...
5955 ]
6056
57+ See :ref: `usage ` for information about how to use ``sphinx-togglebutton ``.
6158
62- The toggle directive
63- --------------------
59+ .. _usage :
6460
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+ =====
6763
68- .. code-block :: rst
64+ There are two main ways to use `` sphinx-togglebutton ``:
6965
70- .. toggle::
66+ * Create dropdown admonitions with the ``dropdown `` class
67+ * Make arbitrary chunks of content "toggle-able" with the ``toggle:: `` directive
7168
72- Here is my toggle-able content!
69+ .. _ dropdown-admonitions :
7370
74- The code above results in:
71+ Dropdown admonitions by adding classes
72+ --------------------------------------
7573
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:
7776
78- Here is my toggle-able content!
77+ .. admonition :: What could be inside this warning?
78+ :class: warning, dropdown
7979
80- You can also add titles to your toggle-able content:
80+ A whale of a joke!
8181
82- .. code-block :: rst
82+ .. image :: https://media.giphy.com/media/FaKV1cVKlVRxC/giphy.gif
8383
84- .. toggle:: My title
84+ (sorry)
8585
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:
8788
88- Which results in:
89+ .. code-block :: rst
8990
91+ .. note::
92+ :class: dropdown
9093
91- .. toggle :: My title
94+ My note
9295
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:
9698
9799.. code-block :: rst
98100
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
108103
109- Here is my toggle-able content!
104+ My note
110105
106+ Creates:
111107
112- Toggling content by adding classes
113- ----------------------------------
108+ .. admonition :: Here's my title
109+ :class: dropdown, warning
114110
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!
118112
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.
120114
121115.. code-block :: rst
122116
123117 .. note::
124- :class: toggle
118+ :class: dropdown, toggle-shown
125119
126120 This is my note.
127121
128- Here's how it looks :
122+ This will generate the following block :
129123
130124.. note ::
131- :class: toggle
125+ :class: dropdown, toggle-shown
132126
133127 This is my note.
134128
135- Clicking on the toggle button will toggle the item's visibility.
129+ .. _ toggle-directive :
136130
131+ Toggle any content with the toggle directive
132+ --------------------------------------------
137133
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:
139136
140137.. code-block :: rst
141138
142- .. note::
143- :class: toggle, toggle-shown
139+ .. toggle::
144140
145- This is my note.
141+ Here is my toggle-able content!
146142
147- This will generate the following block :
143+ The code above results in :
148144
149- .. note ::
150- :class: toggle, toggle-shown
145+ .. toggle ::
151146
152- This is my note.
147+ Here is my toggle-able content!
153148
154- Here's how they look right after one another:
149+ To show the toggle-able content by default, use the `` :show: `` flag.
155150
156- .. note ::
157- :class: toggle
151+ .. code-block :: rst
158152
159- This is my note.
153+ .. toggle::
154+ :show:
160155
161- .. note ::
162- :class: toggle
156+ Here is my toggle-able content!
163157
164- This is my second.
158+ It results in the following:
159+
160+ .. toggle ::
161+ :show:
162+
163+ Here is my toggle-able content!
165164
166165
167166Configuration
@@ -170,42 +169,38 @@ Configuration
170169Below are a few configuration points for ``sphinx-togglebutton ``.
171170
172171
173- Control the selector text used to make elements toggle-able
174- -----------------------------------------------------------
172+ Control the togglebutton hover text
173+ -----------------------------------
175174
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
179177in your ``conf.py `` file:
180178
181179.. code-block :: python
182180
183- togglebutton_selector = " your-selector "
181+ togglebutton_hint = " My text "
184182
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+ =========
188185
189- .. code-block :: python
186+ This is a simple reference section to double-check styling etc.
190187
191- togglebutton_selector = " .toggle, .toggle-this-item "
188+ Here's how they look right after one another:
192189
190+ .. note ::
191+ :class: toggle
193192
194- This is what has been done for the toggle-able section below:
193+ This is my note.
195194
196195.. note ::
197- :class: toggle-this-item
198-
199- A toggled note with a custom class to trigger toggling.
196+ :class: toggle
200197
198+ This is my second.
201199
202- Control the togglebutton hover text
203- -----------------------------------
200+ .. toggle ::
204201
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.
208203
209- .. code-block :: python
204+ .. toggle ::
210205
211- togglebutton_hint = " My text "
206+ This is my second.
0 commit comments