Показать / скрыть часть текста (вопрос / ответ) в файле сфинкса - PullRequest
0 голосов
/ 10 января 2020

Мне было интересно, есть ли способ добавить директиву к документу sphinx со скрытым разделом, который можно открыть одним щелчком мыши.

По сути, вы можете найти что-то вроде https://realpython.com/pandas-python-explore-dataset/ (поиск Показать / Скрыть):

enter image description here

1 Ответ

1 голос
/ 10 января 2020

Вот рабочий пример из Учебной документации Plone .

А вот исходный код .

..  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.

The история изменений показывает, что в тему были добавлены пользовательские 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: " ▲";
}

_templates / 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 %}
...