问题描述
项目结构如下:
index.rst
MyProject
=========
Contents:
.. toctree::
group1
group1.rst
Group1
------
Subgroup1
=========
Subgroup1 contents
Subgroup2
=========
Subgroup2 contents
渲染到(点击Group1
-> Subgroup2
后):
Rendered to (after clicking on Group1
-> Subgroup2
):
如您所见,它将打开 Group1
页面并链接到 Subgroup2
部分.
As you can see it opens the Group1
page and linked to Subgroup2
section.
我想在左侧有相同的(Group1
打开并选择 Subgroup2
)但在右侧我只想看到 Subgroup2代码>页面(没有
Subgroup1
内容的页面).
I want to have the same on the left side (Group1
openned and Subgroup2
choosed) but on the right side I want to see only Subgroup2
page (page without Subgroup1
content).
即有文件 group1/subgroup1.rst
:
Subgroup2
=========
Subgroup2 contents
呈现给:
如何实现?这是一个深度为 2 的简单示例,那么深度 3-4 呢?
How it can be achieved? This is a simple example with the depth 2, what about depth 3-4?
推荐答案
您需要每页内容都有一个文件.Sphinx 不会将文件分成多个页面.
You need to have a file per page of content. Sphinx doesn't break files into multiple pages.
对我有用的是创建引用包含 sub-toctree
指令的文件的 toctree
指令.我喜欢在目录中创建子组,但您可以在一个目录中执行此操作.
What works for me is creating toctree
directives that reference files containing sub-toctree
directives. I like to create the sub-groups in directories, but you could do this within one directory.
index.rst
:
MyProject
=========
Contents:
.. toctree::
group1/index
group1/index.rst
:
Group1
======
.. toctree::
subgroup1
subgroup2
group1/subgroup1.rst
:
Subgroup1
=========
Subgroup1 contents
group1/subgroup2.rst
:
Subgroup2
=========
Subgroup2 contents
这篇关于如何使 toctree 链接像引用小节一样引用单独的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!