是否可以在reST中从子节级别开始自动对节标题进行编号? [英] Is it possible to make automatic section header numbering in reST start at subsection level?

查看:102
本文介绍了是否可以在reST中从子节级别开始自动对节标题进行编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何,有没有获得reST来开始对部分进行编号的功能,例如第二级?我正在使用自动编号设置:

Is there anyway to get reST to start numbering the sections only, at say, the second level? I am using the auto-numbering setting:

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

to output Section A and B's headers unnumbered, but number the subsections (that is, Subsection A.1, A.2 and B.1, B.2).

仔细阅读了文档,似乎可以限制编号的深度,但不能限制编号的起始深度.

Having looked through the documentation, it seems like you can limit how deep the numbering goes, but not at which depth it starts.

推荐答案

Docutils ,参考reStructuredText的实现以及Pelican所基于的实现,没有用于在任意级别上开始段号的选项(据我所知).但是,您可以不使用section-numbering角色,而可以使用一些简单的CSS来设置节标题的样式.这样,您将不会在生成的标记中包含数字,但仍会获得所需的编号.可以找到一篇很好的文章,说明使用 CSS生成的内容计数器 <请在href ="http://philarcher.org/diary/2013/headingnumbers/" rel ="nofollow">此处.基本的CSS是:

Docutils, the reference implementation of reStructuredText and what Pelican is built upon, does not have options for starting section number at arbitrary levels (as far as I can tell). However, rather than relying on the section-numbering role, you could use some simple CSS to style your section headers. This way you would not have the numbers in the generated markup, but you would still get the numbering you are after. A good article demonstrating the use of CSS generated content counters can be found here. The basic CSS is:

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!):

This starts the section numbering at h2 elements, all the way down to h6 elements. All that you should need to do is add the CSS above to one of your stylesheets. This will give you section headers of the form (although I have cheated and just used Markdown here!):

这篇关于是否可以在reST中从子节级别开始自动对节标题进行编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆