如何将单个部分中的Sphinx章节分离到不同的文件中?
问题描述:
我正在使用美妙的狮身人面像工具来创建一些文档,我试图通过将相同部分的章节分隔成单独的文件来保持代码库处于模块化的形式。 (See here for definitions of 'chapter' and 'part'.)如何将单个部分中的Sphinx章节分离到不同的文件中?
我试图做到这一点使用两个文件,test1.rst
:
######
Part 1
######
*********
Chapter 1
*********
Section 1
=========
Test Content 1.
和test2.rst
:
*********
Chapter 2
*********
Section 2
=========
Test Content 2.
它们包含在index.rst
这样的:
.. toctree::
:maxdepth: 2
test1
test2
但是,在构建时,C第2章没有嵌套在第1部分中。这是为什么?有没有办法做到这一点,而不必创建一个脚本来将它们追加到单个文件中,如下面的例子?
例子:
######
Part 1
######
*********
Chapter 1
*********
Section 1
=========
Test Content 1.
*********
Chapter 2
*********
Section 2
=========
Test Content 2.
答
这似乎是include
指令是你在找什么。包含文件的内容被解析并包含在指令的位置。
test1.rst:
######
Part 1
######
*********
Chapter 1
*********
Section 1
=========
Test Content 1.
.. include:: test2.rst
你可以使用'include':http://docutils.sourceforge.net/docs/ref/rst/directives.html#include。 – mzjn
嗨@mzjn如果您可以发布完整答案,我将非常感激,并将其标记为接受的答案。 – AZD