Python sphinx 从主目录树隐藏狮身人面像小节

Python sphinx 从主目录树隐藏狮身人面像小节,python-sphinx,sections,toctree,Python Sphinx,Sections,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 &l

是否可以从主目录树中隐藏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>
Children Title
==============

.. toctree::

   Label of Grandchildren 1
   Label of Grandchildren 2


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

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

Subsection 3
------------
生成这些文件后,将在主目录树中生成:

  • 标签
  • 标签
  • 儿童标签
    • 孙辈标签1
    • 孙辈标签2
    • 第1款
    • 第2款
    • 第3款
我想把这些分段隐藏起来,只保留树木,尽可能多,尽可能深。例如:

  • 标签
  • 标签
  • 儿童标签
    • 孙辈标签1
    • 孙辈标签2
但是,如果单击了与子项标签相关联的超链接,子部分将按常规列出

该“rubric”指令可能实现您想要的:


它不会以完全相同的方式生成章节标题,但至少它们不会显示在TOC中

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

.. toctree::
    :maxdepth: 2

我花了一段时间才弄明白,但我想我终于明白了。“技巧”是您需要在包含toc的父rst和包含节的子rst中设置指令

对于我来说,我将
:maxdepth:1
:titlesonly:
添加到父rst中的toc,然后将
:titlesonly:
添加到子rst中的toc,这非常有效。这使我可以在子目录中设置分层的子目录格式,这些子目录格式被正确地呈现,但不会显示在TOC中。

尝试更改----------------------------为***************子目录1等。此外,您还可以创建多个目录树,每个目录树都有自己的maxdepth,例如

.. toctree::
    :maxdepth: 2

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

.. toctree::
    :maxdepth: 1
    Label of Children TOCTree <path/to/rst/children/file>
。。目录树::
:maxdepth:2
标签
标签
.. 目录树::
:maxdepth:1
子树标签

您可以制作自己的标签

你想要你的标题类型

|start-h3| My Title |end-h3|
在文件写入的末尾

.. |start-h3| raw:: html

     <h3>

.. |end-h3| raw:: html

     </h3>
|start-h3 | raw::html
.. |end-h3 | raw::html

也许
titlesonly
选项就是您要找的。看,我试过了,但它的效果与我想要的完全相反,保留了标题并隐藏了孩子们的目录树。可能是我需要的复制品。实际上,我特别希望
:maxdepth:2
出现在我的
索引.rst
目录树中,但即使是
:titlesonly:
也能很好地抑制我在子页面中定义的小节。