章节分成不同的文件

章节分成不同的文件

本文介绍了如何将单个部分中的 Sphinx 章节分成不同的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用出色的 Sphinx 工具来创建一些文档,并且我试图通过将同一部分的章节分成单独的文件来保持代码库的模块化形式.(参见此处了解章节"和部分"的定义.)

I'm using the wonderful Sphinx tool to create some documentation and I'm trying to keep the codebase in a modular form by separating chapters of the same part into separate files. (See here for definitions of 'chapter' and 'part'.)

我尝试使用两个文件来做到这一点,test1.rst:

I've tried to do this using two files, test1.rst:

######
Part 1
######

*********
Chapter 1
*********

Section 1
=========
Test Content 1.

test2.rst:

*********
Chapter 2
*********

Section 2
=========
Test Content 2.

它们像这样包含在 index.rst 中:

They are included in index.rst like this:

.. toctree::
   :maxdepth: 2

   test1
   test2

但是,在构建时,第 2 章不会嵌套在第 1 部分中.这是为什么呢?有没有办法做到这一点,而不必创建脚本将它们附加到单个文件中,如下例所示?

However, upon build, Chapter 2 doesn't get nested within Part 1. Why is this? Is there any way of doing this without having to create a script to append them into a single file like the example below?

示例:

######
Part 1
######

*********
Chapter 1
*********

Section 1
=========
Test Content 1.

*********
Chapter 2
*********

Section 2
=========
Test Content 2.

推荐答案

include 指令就是你要找的.包含文件的内容被解析并包含在指令点处.

It seems like the include directive is what you are looking for. The included file's content is parsed and included at the point of the directive.

test1.rst:

######
Part 1
######

*********
Chapter 1
*********

Section 1
=========
Test Content 1.

.. include:: test2.rst

这篇关于如何将单个部分中的 Sphinx 章节分成不同的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:42