我有一个包含各种文件夹的目录,每个文件夹中都有 matlab 源文件。其中一些文件夹具有包含 matlab 源文件的子文件夹。
如何使用 Sphinx 创建 TOC 树以嵌套方式包含子文件夹?
例如,当 Main-Directory
包含 conf.py
、index.rst
和 moduleslist.rst
以及以下文件夹结构:
Folder1
abc.m
def.m
Folder2
Folder2.1
ghi.m
jkl.m
使用这个 index.rst
文件:
.. toctree::
:maxdepth: 1
moduleslist
和这个moduleslist.rst
文件:
.. toctree::
:maxdepth: 2
Folder1
=========
.. automodule:: Folder1
:members:
Folder2
=========
.. automodule:: Folder2
:members:
但这不包括子文件夹Folder2.1
和其中的文件。我尝试在 index.rst
中添加 Folder2/index
,Folder2/index.rst
包含 Folder2.1 的自动模块
,其中不包含 ghi.m
的文档。
如何让 Sphinx 在其 TOC 树中显示嵌套的子文件夹?
最佳答案
我已经开始使用 Sphinx 并且在一般文档(不特定于 autodoc 功能)上遇到了这个问题。这就是我让它工作的方式,并且可以更好地控制树的构建方式。
将每个文件夹视为一个单独的组。因此,在 Sphinx 根目录中,您将拥有如下所示的 index.rst 文件:
.. toctree::
:maxdepth: 1
Folder1/index
Folder2/index
我使用 maxdepth: 1
以便它只列出主要组名称。
在 Folder1 和 Folder2 下,您需要添加额外的 index.rst
文件:
#Folder1/index.rst
.. toctree::
:maxdepth: 2
abc.m
def.m
#Folder2/index.rst
.. toctree::
:maxdepth: 2
Folder2.1/index
jkl.m
作为旁注,我设置了我的索引页面,以便它们要么只有组列表 (maxdepth: 1
),要么只有详细信息页面列表 (maxdepth: 2
) - 我确定有一种方法可以使文件夹/索引位于深度 1 和文件位于深度 2。
然后在 Folder2.1
中,您需要第三个索引:
#Folder2.1/index.rst
.. toctree::
:maxdepth: 2
ghi.m
这是 Sphinx Docs on Nested toctree
而且还不是很清楚。显然,对于更复杂/更深的树结构,您需要 autodoc
代码。
关于matlab - 将子文件夹中的文件添加到 sphinx 文档 (sphinxcontrib-matlabdomain),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33486420/