我编写了简单的程序来将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.
显然正在尝试,但我错过了一个参数吗?我是否需要指定所需的转换,例如读者,作家或解析者?
当我使用
运行命令行时,它非常有效rst2html.py <input file> <output file>
答案 0 :(得分:0)
我想我在问题中得到了答案:(
我需要 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)