更多Sphinx定制¶
除了使用核心Sphinx之外,还有两种主要方法可以定制您的文档:扩展和主题。
启用内置扩展¶
除了这些配置值之外,还可以使用以下命令对Sphinx进行更多定制 extensions 。Sphinx运送了几艘 builtin ones ,而且还有更多 maintained by the community 。
例如,要启用 sphinx.ext.duration
扩展名,找到 extensions
在您的列表中 conf.py
并按如下方式添加一个元素:
docs/source/conf.py¶
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.duration',
]
此后,每次生成文档时,您都会在控制台输出的末尾看到一个简短的持续时间报告,如下所示:
(.venv) $ make html
...
The HTML pages are in build/html.
====================== slowest reading durations =======================
0.042 temp/source/index
使用第三方HTML主题¶
另一方面,主题是自定义文档外观的一种方式。Sphinx有几个 builtin themes ,还有 third-party ones 。
例如,要使用 Furo 第三方主题在您的HTML文档中,首先您将需要安装它与 pip
在您的Python虚拟环境中,如下所示:
(.venv) $ pip install furo
然后,找到 html_theme
变量在您的 conf.py
并将其值替换为:
docs/source/conf.py¶
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'furo'
通过此更改,您将注意到您的HTML文档现在有了新的外观:

以Furo为主题的Lumache的HTML文档¶
现在是时候了 expand the narrative documentation and split it into several documents 。