Python 将 sphinx RST 转换为 HTML [英] Python convert sphinx RST to HTML

查看:67
本文介绍了Python 将 sphinx RST 转换为 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这个代码:

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>

因此它不适用于某些特定的 sphinx 指令.

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

对 sphinx RST 文件执行相同操作的最简单方法是什么?

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

更新.好像应该是:

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

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

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

推荐答案

这是我想要做的:

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

这篇关于Python 将 sphinx RST 转换为 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆