Skip to content

Commit 2f2bd88

Browse files
committed
configurable toggle text
1 parent 1be8f95 commit 2f2bd88

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

docs/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,15 @@ Here's how they look right after one another:
162162
:class: toggle
163163

164164
This is my second.
165+
166+
167+
Configuration
168+
=============
169+
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:
173+
174+
.. code-block:: python
175+
176+
togglebutton_hint = "My text"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
license="MIT License",
2525
packages=find_packages(),
2626
package_data={
27-
"sphinx_togglebutton": ["_static/togglebutton.css", "_static/togglebutton.js"]
27+
"sphinx_togglebutton": ["_static/togglebutton.css_t", "_static/togglebutton.js"]
2828
},
2929
install_requires=["setuptools", "wheel", "sphinx", "docutils"],
3030
extras_require={"sphinx": ["myst_nb"]},

sphinx_togglebutton/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def st_static_path(app):
1111
app.config.html_static_path.append(static_path)
1212

1313

14+
def add_to_context(app, config):
15+
# Update the global context
16+
config.html_context.update({'togglebutton_hint': config.togglebutton_hint})
17+
18+
1419
# This function reads in a variable and inserts it into JavaScript
1520
def insert_custom_selection_config(app):
1621
# This is a configuration that you've specified for users in `conf.py`
@@ -58,10 +63,12 @@ def setup(app):
5863
# Add the string we'll use to select items in the JS
5964
# Tell Sphinx about this configuration variable
6065
app.add_config_value("togglebutton_selector", ".toggle", "html")
66+
app.add_config_value("togglebutton_hint", "Click to show", "html")
6167
app.add_js_file("togglebutton.js")
6268

6369
# Run the function after the builder is initialized
6470
app.connect("builder-inited", insert_custom_selection_config)
71+
app.connect("config-inited", add_to_context)
6572
app.add_directive("toggle", Toggle)
6673
return {
6774
"version": __version__,

sphinx_togglebutton/_static/togglebutton.css renamed to sphinx_togglebutton/_static/togglebutton.css_t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ button.toggle-button {
5252
}
5353

5454
button.toggle-button.toggle-button-hidden:before {
55-
content: "Click to show";
55+
content: "{{ togglebutton_hint }}";
5656
position: absolute;
5757
left: -6.5em;
5858
bottom: .4em;

0 commit comments

Comments
 (0)