0

I would like to serve on a flask server an html page with reStructuredText using the sphinx readthedocs theme, rendered on-the-fly from an rst file.

How can I import sphinx as a python module, and then use it together with the readthedocs theme and the input rst string to obtain a string with the HTML rendered content?

This seems to be a standard task, but I have not found any example of such behaviour online. In particular, I would prefer to not first render it on the OS and then read the rendered html file into python, but to directly do this HTML python.

What I have so far using docutils is

from docutils import core
from docutils.writers.html4css1 import Writer

def make_doc(raw_rst):
    _w = Writer()
    return core.publish_string(raw_rst, writer=_w)

and I would like to have the output HTML using the readthedocs theme.

If possible without a hack, I would also prefer to replace the used docutils by sphinx.

Christian
  • 527
  • 6
  • 19
  • 1
    I'm not sure I understand the question, but perhaps this helps: https://stackoverflow.com/a/49222967/407651. – mzjn Jan 17 '19 at 08:12
  • Thanks for the comment, this at least tell me that what I want to do is not officially supported. I try to clarify my question using some pseudocode. – Christian Jan 17 '19 at 09:35

0 Answers0