我编写了简单的程序将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>发布于 2018-01-31 10:04:16
我想我在问题中得到了答案:
我需要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)https://stackoverflow.com/questions/48539024
复制相似问题