reStructuredText不尊重副标题

Wil*_*hes 5 python restructuredtext docutils

这是一个简单的reST片段:

deleting this line causes all subheadings to be rendered as h1 tags

I should be an h1
=================

I should be an h2
-----------------
foo            

I should also be an h2
----------------------
foo
Run Code Online (Sandbox Code Playgroud)

这是一个演示它的演示:

初始行:http
://rst.ninjs.org/?n = f = 66780d732a33c7844f350c240804d0没有初始行:http://rst.ninjs.org/?n = 550ea2c1b4233affdce1d158c5dc4d99

我正在使用以下Python渲染reST:

from docutils.core import publish_parts
parts = publish_parts(rest_content, writer_name="html")
html_snippet = parts['html_body']
Run Code Online (Sandbox Code Playgroud)

如何在<h2>没有初始线的情况下获得副标题(特别是标签)?是否在子标题上方提供了两级层次结构?天真地提供页眉没有帮助:http://rst.ninjs.org/?n = e874f6eaad17c8ae7fd565f9ecb2212b

mkr*_*eli 8

不要将第一个标题提升为文档标题.

请注意以下示例中传递给publish_parts()settings_overrides参数:

rest_content = """
I should be an h1
=================

I should be an h2
-----------------
foo


I should also be an h2
----------------------
foo
"""

from docutils.core import publish_parts
parts = publish_parts(rest_content, writer_name="html",
        settings_overrides={'doctitle_xform':False})
html_snippet = parts['html_body']

print(html_snippet)
Run Code Online (Sandbox Code Playgroud)

并输出:

<div class="document">
<div class="section" id="i-should-be-an-h1">
<h1>I should be an h1</h1>
<div class="section" id="i-should-be-an-h2">
<h2>I should be an h2</h2>
<p>foo</p>
</div>
<div class="section" id="i-should-also-be-an-h2">
<h2>I should also be an h2</h2>
<p>foo</p>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)