如何使用 docutils 从 reStructuredText 创建 HTML?

How to use docutils to create HTML from reStructuredText?

我编写了简单的程序将 reStructuredText 转换为 html

from docutils.core import publish_string

input_string = ("Heading\n"
                "=======\n"
                "\n"
                "1. With 24 widgets pull a **long** one;\n"
                "2. with fewer, push a **wide** one.\n")

html = publish_string(input_string)
print(html)

但输出是:

<document ids="heading" names="heading" source="<string>" title="Heading">
    <title>
        Heading
    <enumerated_list enumtype="arabic" prefix="" suffix=".">
        <list_item>
            <paragraph>
                With 24 widgets pull a 
                <strong>
                    long
                 one;
        <list_item>
            <paragraph>
                with fewer, push a 
                <strong>
                    wide
                 one.

明明是在尝试,但是我是不是少了一个参数?我是否需要指定所需的转换,例如reader,编写器还是解析器?

当我 运行 使用

形成命令行时,它工作得很好
rst2html.py <input file> <output file>

我想我已经找到了问题的答案:(

我需要 writer_name 参数

from docutils.core import publish_string

input_string = ("Heading\n"
                "=======\n"
                "\n"
                "1. With 24 widgets pull a **long** one;\n"
                "2. with fewer, push a **wide** one.\n")

html = publish_string(input_string, writer_name='html')

print(html)