6.6. 下拉框插件 sphinx-togglebutton#
更新时间: 2021-12-21, 11:46:56 | sphinx_togglebutton 版本:
如果需要在 MyST 或 MyST-NB 解析下的 .md
文件下使用选项卡,那么建议使用另一个功能更加强大的插件 Sphinx Design 。
当然,如果只是要使用下拉框功能,那么可以直接使用这个插件。
6.6.1. 安装#
You can install sphinx-togglebutton with pip:
pip install sphinx-togglebutton
Then, activate it in your sphinx build by adding it to your conf.py
configuration file, like so:
extensions = [
...
'sphinx_togglebutton'
...
]
sphinx-togglebutton 专为 sphinx-book-theme 设计。 所以在其他主题中使用可能会出现问题。
6.6.2. 配置:控制切换按钮悬停文本#
当下拉框的内容折叠时,您可以控制其旁边显示的“提示”文本。为此,请在您的 conf.py
文件中使用以下配置变量:
# default value is 'click to show'
togglebutton_hint = "展示隐藏内容"
6.6.3. 语法和效果#
与admonition选项卡一同使用#
与 admonition、note等选项卡一同使用,在选项卡指令中添加选项 class 的属性,如 dropdown
(使用 toggle 并默认隐藏内容) 、 dropdown,toggle-shown
(使用 toggle 并默认显示内容)
```{admonition} What could be inside this warning?
:class: warning, dropdown, toggle-shown
A whale of a joke!

(sorry)
```
.. admonition:: What could be inside this warning?
:class: warning, dropdown, toggle-shown
A whale of a joke!
.. image:: https://media.giphy.com/media/FaKV1cVKlVRxC/giphy.gif
(sorry)
运行结果如下:
What could be inside this warning?
A whale of a joke!
(sorry)
我们可以注意到,我们可以使用自定义标题告诫和应用的“内置”的训诫(例如,风格note,warning用等)admonition
指令。
使用 toggle 指令#
要添加可切换的内容,请使用 toggle
指令。该指令将其内容包装在一个可切换的容器中。要默认显示可切换的内容,请使用 :show:
标志。
```{toggle}
:show:
Here is my toggle-able content!
```
.. toggle::
:show:
Here is my toggle-able content!
Here is my toggle-able content!
渲染结果如下:
Here is my toggle-able content!