Domanda

I want to parse .rst files to .html files on the fly to display as a webpage. I'm using pyramid, and I haven't found any quick help on how to use docutils inside python code and make it write to a buffer.

Anyone have any links to a simple tutorial or any other suggestions on how to do that?

È stato utile?

Soluzione

One way is to do something like:

>>> 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'
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top