防止 sphinx 重新开始对每个文件进行编号

Prevent sphinx from restarting section numbering every file

我的索引文件设置如下:

Doc Title
==============================

..toctree::
   :maxdepth: 3
   :numbered:
   :caption: Contents

   01_file1
   01.3_file2

如果内容是这样...

01_file1.txt:

Level 1 section title
--------------------------------------------

Level 2 section title
............................................

Another Level 2 section title
............................................

和 01.3_file2.txt:

A third Level 2 section title
............................................

我希望如此,因为 Sphinx 将所有内容都视为单个文档:

1. Level 1 section title
  1.1 Level 2 section title
  1.2 Another Level 2 section title
  1.3 A third Level 2 section title

但我得到的是:

1. Level 1 section title
  1.1 Level 2 section title
  1.2 Another Level 2 section title
2. A third Level 2 section title

我猜这是因为 Sphinx(或者可能 reST/Markdown?)在每个新文本文件中重新启动隐式标题级别。有没有办法得到我真正想要的东西?

引用 reST documentation...

Rather than imposing a fixed number and order of section title adornment styles, the order enforced will be the order as encountered. The first style encountered will be an outermost title (like HTML H1), the second style will be a subtitle, the third will be a subsubtitle, and so on.

parent 文件决定其包含的 children 的标题级别。要达到预期的效果,请从 index 中删除 01.3_file2,然后在 01_file1.txt 中您要包含它的位置放置一个 .. include:: 01.3_file2


索引:

Doc Title
==============================

..toctree::
   :maxdepth: 3
   :numbered:
   :caption: Contents

   01_file1

01_file1.txt:

Level 1 section title
--------------------------------------------

Level 2 section title
............................................

Another Level 2 section title
............................................

.. include:: 01.3_file2.txt

01.3_file2.txt:

A third Level 2 section title
............................................

结果:

1. Level 1 section title
  1.1 Level 2 section title
  1.2 Another Level 2 section title
  1.3 A third Level 2 section title