隐藏主TOCTree中的Sphinx子部分

Bru*_*sto 11 documentation tableofcontents python-sphinx

是否可以隐藏主TOCTree中RST文件中存在的一个(或所有)子部分?

让我再描述一下:

index.rst

:doc:`Label <path/to/rst/file>`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. toctree::

   Label <path/to/rst/file>
   Label <path/to/rst/file>

   Label of Children TOCTree <path/to/rst/children/file>
Run Code Online (Sandbox Code Playgroud)

儿童/ file.rst

Children Title
==============

.. toctree::

   Label of Grandchildren 1
   Label of Grandchildren 2


Subsection 1
------------

Subsection 2
------------

Subsection 3
------------
Run Code Online (Sandbox Code Playgroud)

构建完成后,这些文件将在主TOCTree中生成:

  • 标签
  • 标签
  • 儿童的标签
    • 孙子的标签1
    • 孙子2的标签
    • 第1小节
    • 第2小节
    • 第3小节

而且我想隐藏分段,只保留TOCTrees,尽可能多和深.例如:

  • 标签
  • 标签
  • 儿童的标签
    • 孙子的标签1
    • 孙子2的标签

但是,如果点击与儿童标签相关联的超链接,则会像往常一样列出子部分;

Bri*_*den 8

这花了我一段时间才弄明白,但我想我终于明白了."技巧"是你需要在包含toc的父rst和包含该部分的子rst中设置指令.

对于我来说,我加入:maxdepth:1:titlesonly:在父第一个TOC中,然后:titlesonly:在孩子的TOC,和完美的作品.这允许我在子项中具有分层子格式格式,该格式正确呈现,而不会显示在TOC中.


den*_*rsc 7

"rubric"指令可以达到你想要的效果:

http://sphinx-doc.org/markup/para.html#directive-rubric

它不会以完全相同的方式生成部分标题,但至少它们不会出现在TOC中


dev*_*n_s 5

您可以使用maxdepth参数toctree来设置 TOC 的深度:

.. toctree::
    :maxdepth: 2
Run Code Online (Sandbox Code Playgroud)