无论如何,有没有办法让reST开始仅对第二级的部分进行编号?我正在使用自动编号设置:
.. section-numbering::
我想要的是输入:
Section A
=========
Subsection A.1
------------
Subsection A.2
------------
Section B
=========
Subsection B.1
------------
Subsection B.2
------------
输出未编号的节 A 和 B 的标题,但对小节进行编号(即小节 A.1、A.2 和 B.1、B.2)。
查看文档后,您似乎可以限制编号的深度,但不能限制其开始的深度。
最佳答案
Docutils ,reStructuredText 的引用实现以及 Pelican 的构建基础,没有在任意级别开始节号的选项(据我所知)。但是,您可以使用一些简单的 CSS 来设置节标题的样式,而不是依赖 section-numbering
角色。这样,您就不会在生成的标记中获得数字,但您仍然会获得所需的编号。一篇很好的文章演示了 CSS generated content counters 的使用可以查到here 。基本的 CSS 是:
body {counter-reset: h2}
h2 {counter-reset: h3}
h3 {counter-reset: h4}
h4 {counter-reset: h5}
h5 {counter-reset: h6}
h2:before {counter-increment: h2; content: counter(h2) ". "}
h3:before {counter-increment: h3; content: counter(h2) "." counter(h3) ". "}
h4:before {counter-increment: h4; content: counter(h2) "." counter(h3) "." counter(h4) ". "}
h5:before {counter-increment: h5; content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". "}
h6:before {counter-increment: h6; content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "}
这从 h2
元素开始对节进行编号,一直到 h6
元素。您需要做的就是将上面的 CSS 添加到您的样式表之一。这将为您提供表单的部分标题(尽管我已经作弊并且只是在这里使用了 Markdown!):
h1
元素
1。 h2
元素
1.1 h3
元素
1.2 h3
元素
2。 h2
元素
2.1 h3
元素
2.2 h3
元素
2.2.1 h4
元素
h1
元素
关于restructuredtext - 是否可以在 reST 中从小节级别开始自动进行节标题编号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22212848/