首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用docutils从reStructuredText创建HTML?

如何使用docutils从reStructuredText创建HTML?
EN

Stack Overflow用户
提问于 2018-01-31 09:46:25
回答 1查看 503关注 0票数 0

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

代码语言:javascript
复制
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)

但产出如下:

代码语言:javascript
复制
<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.

这显然是在尝试,但我是不是遗漏了一个参数?我是否需要指定所需的转换,例如读者、作者或解析器?

当我从命令行运行时,它运行得非常完美。

代码语言:javascript
复制
rst2html.py <input file> <output file>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-31 10:04:16

我想我在问题中得到了答案:

我需要writer_name参数

代码语言:javascript
复制
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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48539024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档