Show/hide sphinx 文件中的部分文本 (question/answer)

Show/hide part of text (question/answer) in sphinx file

我想知道是否有一种方法可以将指令添加到带有可以通过单击打开的隐藏部分的 sphinx 文档。

基本上您可以找到 https://realpython.com/pandas-python-explore-dataset/(搜索 Show/Hide):

这是来自 Mastering Plone Training documentation 的工作示例。

这是 source code

..  admonition:: Solution
    :class: toggle
    * Go to the dexterity-controlpanel (http://localhost:8080/Plone/@@dexterity-types)
    * Click on *Page* (http://127.0.0.1:8080/Plone/dexterity-types/Document)
    * Select the tab *Behaviors* (http://127.0.0.1:8080/Plone/dexterity-types/Document/@@behaviors)
    * Check the box next to *Lead Image* and save.

commit history 表明已将自定义 JavaScript 和样式添加到主题中。

_static/custom.css

.toggle {
    background: none repeat scroll 0 0 #e7f2fa;
}

.toggle .admonition-title {
    display: block;
    clear: both;
}

.toggle .admonition-title:after {
    content: " ▼";
}

.toggle .admonition-title.open:after {
    content: " ▲";
}

_模板/page.html

{% set css_files = css_files + ["_static/custom.css"] %}

{%- block extrahead %}
 <script type="text/javascript">
    $(document).ready(function() {
        //
        //
        $(".toggle > *").hide();
        $(".toggle .admonition-title").show();
        $(".toggle .admonition-title").click(function() {
            $(this).parent().children().not(".admonition-title").toggle(400);
            $(this).parent().children(".admonition-title").toggleClass("open");
        })
    });
</script>
{% endblock %}