首页 > 解决方案 > Sphinx toctree 指令:如何隐藏标题不被显示?

问题描述

如果我有以下内容index.rst

This Section
------------

.. toctree::
   :caption: This Section
   :maxdepth: 1

   this_section/intro
   this_section/body
   this_section/outro

然后“本节”将在生成的 HTML 文件中出现两次:一个是<h1>,一个是<p class="caption">. 我怎样才能摆脱后者,或者:caption:生成一个<h1>?我不能简单地删除:caption:,因为侧边栏(我正在使用 ReadTheDoc 主题)依赖此选项来正确生成 TOC 树。

标签: python-sphinxcaptiontoctree

解决方案


我最终通过将其添加到目录中来使用 css 删除custom.css_static

section#setup span.caption-text {
    display: none;
}

并在我的conf.py

html_static_path = ['_static']
html_css_files = ['custom.css']

推荐阅读