公用程序¶
Sphinx提供实用程序类和函数来开发插件。
组件的基类¶
这些基类有助于插件轻松获取Sphinx组件(例如:class:.Config,:class:`.BuildEnvironment`等等)。
备注
它们的子类可能无法与裸docutil一起工作,因为它们与Sphinx强耦合。
- class sphinx.transforms.SphinxTransform(document, startnode=None)[源代码]¶
变换的基类。
与``docutils.transforms.Transform``相比,该类改进了Sphinx接口的可访问性。
- property env: BuildEnvironment¶
对:类:`.BuildEnvironment`对象的引用。
- class sphinx.transforms.post_transforms.SphinxPostTransform(document, startnode=None)[源代码]¶
后转换的基类。
Post transforms are invoked to modify the document to restructure it for outputting. They resolve references, convert images, do special transformation for each output formats and so on. This class helps to implement these post transforms.
- class sphinx.util.docutils.SphinxDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[源代码]¶
Sphinx指令的基类。
这个类为Sphinx指令提供了助手方法。
备注
此类的子类可能无法与docutils一起使用。这个类与Sphinx紧密耦合。
- property env: BuildEnvironment¶
对:类:`.BuildEnvironment`对象的引用。
- class sphinx.util.docutils.SphinxRole[源代码]¶
sphinx角色的基类。
此类为Sphinx角色提供帮助程序方法。
备注
此类的子类可能无法与docutils一起使用。这个类与Sphinx紧密耦合。
- content: Sequence[str]¶
A list of strings, the directive content for customisation (from the “role” directive).
- property env: BuildEnvironment¶
对:类:`.BuildEnvironment`对象的引用。
- inliner: Inliner¶
在``docutils.parsers.rst.状态。内联线``对象。
- class sphinx.util.docutils.ReferenceRole[源代码]¶
引用角色的基类。
The reference roles can accept
link title <target>
style as a text for the role. The parsed result; link title and target will be stored toself.title
andself.target
.
- class sphinx.transforms.post_transforms.images.ImageConverter(document, startnode=None)[源代码]¶
图像转换器的基类。
An image converter is kind of Docutils transform module. It is used to convert image files which are not supported by a builder to the appropriate format for that builder.
For example,
LaTeX builder
supports PDF, PNG and JPEG as image formats. However it does not support SVG images. For such case, using image converters allows to embed these unsupported images into the document. One of the image converters; sphinx.ext.imgconverter can convert a SVG image to PNG format using Imagemagick internally.制作自定义图像转换器有三个步骤:
生成“ImageConverter”类的子类
重写“转换规则”、“is_available()”和“convert()``
使用:py:meth:将图像转换器注册到Sphinx。Sphinx.add_post_转换
- convert(_from: str, _to: str) bool [源代码]¶
Convert an image file to the expected format.
_from is a path of the source image file, and _to is a path of the destination file.
- conversion_rules: list[tuple[str, str]] = []¶
图像转换器支持的转换规则。它表示为源图像格式(mimetype)和目标图像格式对的列表:
conversion_rules = [ ('image/svg+xml', 'image/png'), ('image/gif', 'image/png'), ('application/pdf', 'image/png'), ]
- default_priority = 200¶
Numerical priority of this transform, 0 through 999 (override).
公用程序组件¶
Utility types¶
- class sphinx.util.typing.ExtensionMetadata[源代码]¶
The metadata returned by an extension’s
setup()
function.See 扩展元数据.
- parallel_read_safe: bool¶
Indicate whether parallel reading of source files is supported by the extension.