xcorat
xcorat

Reputation: 1472

parsing rST to HTML on the fly using Docutils

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?

Upvotes: 6

Views: 1789

Answers (2)

G. Milde
G. Milde

Reputation: 862

The Publisher convenience functions are the normal entry points for using Docutils as a library. They are documented in The Docutils Publisher.

Upvotes: 0

Jon Clements
Jon Clements

Reputation: 142106

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'

Upvotes: 12

Related Questions