网页
综合
更新时间 2026-11-14 16:31:17
Application API — Sphinx documentation
自动蜘蛛
www.sphinx-doc.org
正文约 3051 字
Each Sphinx extension is a Python module with at least a setup() function. This function is called at initialization time with one argument, the application object representing the Sphinx process.
This application object has the public API described in the following.
These methods are usually called in an extension’s setup() function.
Examples of using the Sphinx extension API can be seen in the sphinx.ext package.
Import and setup a Sphinx extension module.
Load the extension given by the module name. Use this if your extension needs the features provided by another extension. No-op if called twice.
Check the Sphinx version if requested.
Compare version with the version of the running Sphinx, and abort the build when it is too old.
version – The required version in the form of major.minor or (major, minor).
Added in version 1.0.
Changed in version 7.1: Type of version now allows (major, minor) form.
Register callback to be called when event is emitted.
For details on available core events and the arguments of callback functions, please see Event callbacks API.
event – The name of target event
callback – Callback function for the event
priority – The priority of the callback. The callbacks will be invoked in order of priority (ascending).
A listener ID. It can be used for disconnect().
Changed in version 3.0: Support priority
Unregister callback by listener_id.
listener_id – A listener_id that connect() returns
Register a new builder.
builder – A builder class
override – If true, install the builder forcedly even if another builder is already installed as the same name
Changed in version 1.8: Add override keyword.
Register a configuration value.
This is necessary for Sphinx to recognize new values and set default values accordingly.
name – The name of the configuration value. It is recommended to be prefixed with the extension name (ex. html_logo, epub_title)
default – The default value of the configuration.
The condition of rebuild. It must be one of those values:
'env' if a change in the setting only takes effect when a document is parsed – this means that the whole environment must be rebuilt.
'html' if a change in the setting needs a full rebuild of HTML documents.
'' if a change in the setting will not need any special rebuild.
types – The type of configuration value. A list of types can be specified. For example, [str] is used to describe a configuration that takes string value.
description – A short description of the configuration value.
Changed in version 0.4: If the default value is a callable, it will be called with the config object as its argument in order to get the default value. This can be used to implement config values whose default depends on other values.
Changed in version 0.6: Changed rebuild from a simple boolean (equivalent to '' or 'env') to a string. However, booleans are still accepted and converted internally.
Added in version 1.4: The types parameter.
Added in version 7.4: The description parameter.
Register an event called name.
This is needed to be able to emit it.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。