使用Docutils即时解析rST到HTML

xco*_*rat 6 python docutils pyramid

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

任何人都有任何链接到一个简单的教程或任何其他建议如何做到这一点?

Jon*_*nts 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'
Run Code Online (Sandbox Code Playgroud)