Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python convert sphinx RST to HTML

I have tried this code:

from docutils.core import publish_string
text = publish_string(open(file_path, 'r').read(), writer_name='html')

But it says:

<p>Unknown directive type &quot;toctree&quot;.</p>

So it won't work with some specific sphinx directives.

What is the easiest way to do same stuff for sphinx RST files?

upd. Seems like it must be:

sphinx-build -b singlehtml -D extensions='sphinx.ext.autodoc' -D master_doc='index' -C /mypath/docs .

How can I call that from Python code instead of console?

like image 426
StackUser Avatar asked Mar 11 '26 22:03

StackUser


1 Answers

Here is what i wanted to do:

import sphinx
args = ". -b singlehtml -D extensions=sphinx.ext.autodoc -D master_doc=index -C /tmp/doc /tmp/out"
sphinx.main(args.split())
result = open('/tmp/out/index.html', 'r')
like image 132
StackUser Avatar answered Mar 14 '26 04:03

StackUser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!