sphinx.ext.ifconfig – 基于配置包含内容

这个扩展非常简单,只包含一个指令

警告

此指令旨在仅控制文档的内容。它无法控制章节、标签等。

.. ifconfig::

仅当作为参数给出的 Python 表达式为 True 时,才包含指令的内容,该表达式在项目配置的命名空间中求值(即,conf.py 中的所有已注册变量均可用)。

例如,可以这样写

.. ifconfig:: releaselevel in ('alpha', 'beta', 'rc')

   This stuff is only included in the built docs for unstable versions.

要使自定义配置值对 Sphinx 可见,请在 conf.py 的 setup 函数中使用 add_config_value(),例如:

def setup(app):
    app.add_config_value('releaselevel', '', 'env')

第二个参数是默认值,第三个参数对于此类值应始终为 'env'(它选择在值更改时 Sphinx 是否重新读取文档)。