【问题标题】:Prevent sphinx from restarting section numbering every file防止 sphinx 重新启动每个文件的节编号
【发布时间】:2019-03-09 04:58:18
【问题描述】:

我的索引文件是这样设置的:

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

不是强加固定数量和顺序的部分标题装饰样式,而是强制执行的顺序将是遇到的顺序。遇到的第一个样式是最外层的标题(如 HTML H1),第二个样式是副标题,第三个是副标题,以此类推。

【问题讨论】:

    标签: python-sphinx restructuredtext sections toctree


    【解决方案1】:

    父文件确定其包含的子文件的标题级别。要达到预期的效果,请从index 中删除01.3_file2,然后将.. include:: 01.3_file2 添加到01_file1.txt 中要包含它的位置。


    索引:

    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
    

    【讨论】:

    • 完全正确。我已经用你所描述的演示更新了你的答案。
    猜你喜欢
    • 2013-01-06
    • 1970-01-01
    • 2022-11-24
    • 2023-02-06
    • 2022-12-13
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多