restructuredtext - 是否可以在 reST 中从小节级别开始自动进行节标题编号?

标签 restructuredtext pelican

无论如何,有没有办法让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/

相关文章:

python-sphinx - 将 Sphinx TOC 分成带有副标题的小节

python-sphinx - 错误 "rubric"指令中没有内容被允许

python-sphinx - Sphinx 3 级以上标题的节编号:.. sectnum::

python - 如何找到 wx.CheckBoxState 的 intersphinx 映射

Python Pelican 订单菜单项

python - 使用 Python setup.py 通过 develop 与 install 安装不同的依赖项

blogs - 在 Pelican 中,如何在主页上显示完整的最新文章/帖子?

restructuredtext - 当术语以序数形式的数字开头时,如何区分定义列表和有序列表?

python - 如何自动删除 Pelican CMS 中的 "Powered by ..."?

python - 为什么我会收到 python ImportError : No module named html_parser?