简体   繁体   English

防止 sphinx 重新启动每个文件的节编号

[英]Prevent sphinx from restarting section numbering every file

I've got my index file set up like so:我的索引文件设置如下:

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

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

   01_file1
   01.3_file2

If the contents are thus...如果内容是这样...

01_file1.txt: 01_file1.txt:

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

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

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

and for 01.3_file2.txt:对于 01.3_file2.txt:

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

I would expect this because Sphinx treats everything as a single document:我希望这是因为 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

But instead I get this:但是我得到了这个:

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

I'm guessing this is because Sphinx (or maybe reST/Markdown?) restarts implicit heading levels with each new text file.我猜这是因为 Sphinx(或者可能是 reST/Markdown?)为每个新文本文件重新启动隐式标题级别。 Is there a way to get what I actually want?有没有办法得到我真正想要的?

Quoting the reST documentation ...引用reST 文档...

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.遇到的第一个样式将是最外层的标题(如 HTML H1),第二个样式将是副标题,第三个将是副标题,依此类推。

The parent file determines the heading level of its included children.父文件确定其包含的子文件的标题级别。 To achieve the desired effect, remove 01.3_file2 from index , and place an .. include:: 01.3_file2 in 01_file1.txt at the point where you want to include it.要达到预期的效果, 01.3_file2index删除01.3_file2 ,并在01_file1.txt中要包含它的位置放置一个.. include:: 01.3_file2


index:指数:

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

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

   01_file1

01_file1.txt: 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: 01.3_file2.txt:

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

Results in:结果是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM