首页 > 解决方案 > 如何使用 rst2html 创建适当的标题级别

问题描述

我不明白为什么:

H1: document title
##################

Sample H2
*********
Sample content.

结果是:

<div class="document" id="h1-document-title">
<h1 class="title">H1: document title</h1>
<h2 class="subtitle" id="sample-h2">Sample H2</h2>

<p>Sample content.</p>
</div>

然而

H1: document title
##################

Sample H2
*********
Sample content.

Sample H3
*********
Sample content.

结果是:

<div class="document" id="h1-document-title">
<h1 class="title">H1: document title</h1>

<div class="section" id="sample-h2">
<h1>Sample H2</h1>
<p>Sample content.</p>
</div>
<div class="section" id="sample-h3">
<h1>Sample H3</h1>
<p>Sample content.</p>
</div>

即我不能有一个h1 元素后跟一个以上的h2。谢谢。

标签: htmlrestructuredtextdocutils

解决方案


这是关于文档标题和副标题的解释。如果第一个标题的修饰在文档中是唯一的,则将其解释为文档标题。如果在第一个标题之后紧接着有另一个带有独特装饰的第二个标题,则将其视为副标题。

请参阅http://docutils.sourceforge.net/docs/user/rst/quickstart.html#document-title-subtitle

例子:

Document title
##############

Subtitle
.........

Heading 1
*********
Sample content.

Heading 2
---------
Sample content.

Heading 3
---------
Sample content.

通过这个标记,rst2html 将生成带有如下标题的 HTML:

  • 文件标题:(<h1>居中)
  • 副标题:(<h2>居中)
  • 标题 1:<h1>
  • 标题 2:<h2>
  • 标题 3:<h2>

推荐阅读