How to separate Sphinx chapters within a single part into different files?

泄露秘密 提交于 2019-12-10 17:12:15

问题


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'.)

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

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

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

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

and test2.rst:

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

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

They are included in index.rst like this:

.. toctree::
   :maxdepth: 2

   test1
   test2

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?

Example:

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

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

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

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

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

回答1:


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


来源:https://stackoverflow.com/questions/46791625/how-to-separate-sphinx-chapters-within-a-single-part-into-different-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!