Python sphinx Python将sphinx RST转换为HTML

Python sphinx Python将sphinx RST转换为HTML,python-sphinx,restructuredtext,docutils,Python Sphinx,Restructuredtext,Docutils,我尝试过以下代码: from docutils.core import publish_string text = publish_string(open(file_path, 'r').read(), writer_name='html') 但它说: <p>Unknown directive type &quot;toctree&quot;.</p> 如何从Python代码而不是控制台调用它?以下是我想要做的: import sphinx args

我尝试过以下代码:

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

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

如何从Python代码而不是控制台调用它?

以下是我想要做的:

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')

下面是另一个例子:

#斯芬克斯版本=2.3.1
#Python版本=3.7.3
从sphinx.cmd.build导入main作为sphinx_main
从pathlib导入路径
从操作系统导入开始文件
导入系统
主文档='索引'
source_后缀='.rst'
输出文件='tmp/dist'
html_主题='nature'
build_format='html'#singlehtml。。。
args=f.“-b{build_format}-D extensions=sphinx.ext.autodoc”\
f“-D主文档={master\u doc}”\
f“-D source_后缀={source_后缀}”\
f“-D html_主题={html_主题}”\
f“-C{output_file}”
sys.path.append(str(路径('.').absolute())
sphinx_main(args.split())
startfile(路径(输出文件).joinpath(主文档+'.html'))
更多参数>

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')