HTML rST parsing on the fly using Docutils

I want to parse .rst files into .html files on the fly to display them as a web page. I am using a pyramid, and I did not find any quick help on how to use docutils inside python code and get it to write to the buffer.

Does anyone have links to a simple tutorial or any other suggestions on how to do this?

+6
source share
1 answer

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' 
+12
source

Source: https://habr.com/ru/post/945182/


All Articles