Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 554
xcorat Avatar asked May 16 '13 16:05

xcorat


1 Answers

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'
like image 88
Jon Clements Avatar answered Nov 10 '22 18:11

Jon Clements