使用 Docutils 即时将 rST 解析为 HTML

问题描述 投票:0回答:2
我想即时将 .rst 文件解析为 .html 文件以显示为网页。我正在使用金字塔,但我还没有找到任何有关如何在 python 代码中使用 docutils 并将其写入缓冲区的快速帮助。

有人有简单教程的链接或有关如何执行此操作的任何其他建议吗?

python pyramid docutils
2个回答
12
投票
一种方法是执行以下操作:

>>> 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'
    

0
投票

Publisher 便利功能 是使用 Docutils 作为库的正常入口点。它们记录在The Docutils Publisher中。

© www.soinside.com 2019 - 2024. All rights reserved.