gpt4 book ai didi

python - 使用 Docutils 将 rST 动态解析为 HTML

转载 作者:太空狗 更新时间:2023-10-29 22:13:34 34 4
gpt4 key购买 nike

我想即时将 .rst 文件解析为 .html 文件以显示为网页。我正在使用 Pyramid ,但我还没有找到任何关于如何在 python 代码中使用 docutils 并将其写入缓冲区的快速帮助。

有人有指向简单教程的链接或关于如何操作的任何其他建议吗?

最佳答案

一种方法是做类似的事情:

>>> a = """=====\nhello\n=====\n\n - one\n - two\n"""
>>> import docutils
>>> docutils.core.publish_parts(a, writer_name='html')['html_body']
u'<div class="document" id="hello">\n<h1 class="title">hello</h1>\n<blockquote>\n<ul class="simple">\n<li>one</li>\n<li>two</li>\n</ul>\n</blockquote>\n</div>\n'

关于python - 使用 Docutils 将 rST 动态解析为 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16592991/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com