Sphinx 添加的 Doctree 节点类¶
特定于域的对象描述节点¶
顶层节点¶
这些节点构成了对象描述的最顶层级别。
- class sphinx.addnodes.desc(rawsource='', *children, **attributes)[源代码]¶
用于对象签名列表及其通用描述的节点。
包含一个或多个
desc_signature
节点,然后是单个desc_content
节点。此节点始终具有两个类
它所属的域的名称,例如,
py
或cpp
。域中对象类型的名称,例如,
function
。
- class sphinx.addnodes.desc_signature(*args: Any, **kwargs: Any)[源代码]¶
用于单个对象签名的节点。
默认情况下,签名是单行签名。设置
is_multiline = True
以描述多行签名。在这种情况下,所有子节点都必须是desc_signature_line
节点。此节点始终具有类
sig
、sig-object
和它所属的域。
- class sphinx.addnodes.desc_signature_line(rawsource='', text='', *children, **attributes)[源代码]¶
用于多行对象签名中的行的节点。
它应该仅用作
desc_signature
的子项,并且is_multiline
设置为True
。为应该获取永久链接的行设置add_permalink = True
。
签名中高层结构的节点¶
这些节点出现在非多行 desc_signature
节点和 desc_signature_line
节点中。
- class sphinx.addnodes.desc_name(*args: Any, **kwargs: Any)[源代码]¶
用于主对象名称的节点。
例如,在 Python 类
MyModule.MyClass
的声明中,主名称是MyClass
。此节点始终具有类
sig-name
。
- class sphinx.addnodes.desc_addname(*args: Any, **kwargs: Any)[源代码]¶
用于对象的其他名称部分的节点。
例如,在 Python 类
MyModule.MyClass
的声明中,附加名称部分是MyModule.
。此节点始终具有类
sig-prename
。
- class sphinx.addnodes.desc_type(rawsource='', text='', *children, **attributes)[源代码]¶
用于返回类型或对象类型名称的节点。
- class sphinx.addnodes.desc_returns(rawsource='', text='', *children, **attributes)[源代码]¶
用于 “returns” 注释的节点(类似于 Python 中的 ->)。
- class sphinx.addnodes.desc_parameterlist(rawsource='', text='', *children, **attributes)[源代码]¶
用于通用参数列表的节点。
默认情况下,参数列表与签名的其余部分内联编写。设置
multi_line_parameter_list = True
以描述多行参数列表。在这种情况下,每个参数都将写在自己的缩进行上。如果multi_line_trailing_comma
为 True,则将在最后一行添加尾随逗号。
- class sphinx.addnodes.desc_parameter(rawsource='', text='', *children, **attributes)[源代码]¶
用于单个参数的节点。
签名文本元素的节点¶
这些节点继承 desc_sig_element
,并且通常通过 SigElementFallbackTransform
转换为 docutils.nodes.inline
。
扩展可以创建额外的类似 desc_sig_*
的节点,但是为了使 SigElementFallbackTransform
将它们自动转换为内联节点,必须通过 desc_sig_element
的类关键字参数 _sig_element=True
将它们添加到 SIG_ELEMENTS
,例如
class desc_custom_sig_node(desc_sig_element, _sig_element=True): ...
为了向后兼容,仍然可以使用 SIG_ELEMENTS.add(desc_custom_sig_node)
直接添加节点。
- sphinx.addnodes.SIG_ELEMENTS: set[type[desc_sig_element]]¶
继承
desc_sig_element
的类集合。如果构建器的转换器类不继承自 SphinxTranslator,则每个节点类都应由构建器的转换器类处理。此集合可以由第三方扩展手动扩展,或者通过子类化
desc_sig_element
并使用类关键字参数 _sig_element=True 来扩展。
- class sphinx.addnodes.desc_sig_element(rawsource: str = '', text: str = '', *children: Element, **attributes: Any)[源代码]¶
签名的内联文本节点的公共父类。
- class sphinx.addnodes.desc_sig_space(rawsource: str = '', text: str = ' ', *children: Element, **attributes: Any)[源代码]¶
用于签名中空格的节点。
- class sphinx.addnodes.desc_sig_name(rawsource: str = '', text: str = '', *children: Element, **attributes: Any)[源代码]¶
用于签名中标识符的节点。
- class sphinx.addnodes.desc_sig_operator(rawsource: str = '', text: str = '', *children: Element, **attributes: Any)[源代码]¶
用于签名中运算符的节点。
- class sphinx.addnodes.desc_sig_punctuation(rawsource: str = '', text: str = '', *children: Element, **attributes: Any)[源代码]¶
用于签名中标点符号的节点。
- class sphinx.addnodes.desc_sig_keyword(rawsource: str = '', text: str = '', *children: Element, **attributes: Any)[源代码]¶
用于签名中通用关键字的节点。
- class sphinx.addnodes.desc_sig_keyword_type(rawsource: str = '', text: str = '', *children: Element, **attributes: Any)[源代码]¶
用于签名中作为内置类型的关键字的节点。
- class sphinx.addnodes.desc_sig_literal_number(rawsource: str = '', text: str = '', *children: Element, **attributes: Any)[source]¶
签名中数值字面量的节点。
类似公告的新结构¶
其他段落级节点¶
新的内联节点¶
- class sphinx.addnodes.index(rawsource='', text='', *children, **attributes)[source]¶
索引条目的节点。
此节点由
index
指令创建,并具有一个属性entries
。它的值是一个包含 5 元组的列表,格式为(entrytype, entryname, target, ignored, key)
。entrytype 是 “single”、“pair”、“double”、“triple” 之一。
key 是通用索引页面的分类字符(通常是单个字符)。有关此项的详细信息,另请参阅:
glossary
和 https://github.com/sphinx-doc/sphinx/pull/2320。
- class sphinx.addnodes.pending_xref(rawsource='', *children, **attributes)[source]¶
用于跨引用的节点,这些跨引用在没有关于所有文档的完整信息的情况下无法解析。
这些节点在写入输出之前在 BuildEnvironment.resolve_references 中解析。
- class sphinx.addnodes.pending_xref_condition(rawsource='', text='', *children, **attributes)[source]¶
节点表示创建交叉引用的潜在方法以及应使用此方法的条件。
此节点仅允许放置在
pending_xref
节点下。pending_xref 节点必须不包含 pending_xref_condition 节点,或者只能包含 pending_xref_condition 节点。交叉引用解析器将包含 pending_xref_condition 节点的
pending_xref
替换为这些 pending_xref_condition 节点内容之一的内容。它使用 condition 属性来决定使用哪个 pending_xref_condition 节点的内容。例如,让我们考虑一下交叉引用解析器如何作用于<pending_xref refdomain="py" reftarget="io.StringIO ...> <pending_xref_condition condition="resolved"> <literal> StringIO <pending_xref_condition condition="*"> <literal> io.StringIO
如果交叉引用解析器成功解析了交叉引用,则它将 pending_xref 重写为
<reference> <literal> StringIO
否则,如果交叉引用解析失败,则它将 pending_xref 重写为
<reference> <literal> io.StringIO
pending_xref_condition 节点应具有 condition 属性。域可以将它们各自的条件存储到属性中,以在解析阶段过滤内容。作为保留条件名称,
condition="*"
用于解析失败的回退。此外,作为推荐的条件名称,condition="resolved"
表示 intersphinx 模块中的解析成功。在 4.0 版本中添加。
特殊节点¶
- class sphinx.addnodes.only(rawsource='', *children, **attributes)[source]¶
用于 “only” 指令的节点(基于标签的条件包含)。
- class sphinx.addnodes.highlightlang(rawsource='', *children, **attributes)[source]¶
插入以设置后续代码块的突出显示语言和行号选项。
您不应需要在扩展中生成以下节点。
- class sphinx.addnodes.start_of_file(rawsource='', *children, **attributes)[source]¶
用于标记新文件开始的节点,仅在 LaTeX 构建器中使用。