A Domain is meant to be a group of “object” description directives for objects of a similar nature, and corresponding roles to create references to them. Examples would be Python modules, classes, functions etc., elements of a templating language, Sphinx roles and directives, etc.
Each domain has a separate storage for information about existing objects and how to reference them in self.data, which must be a dictionary. It also must implement several functions that expose the object information in a uniform way to parts of Sphinx that allow the user to reference or search for objects in a domain-agnostic way.
About self.data: since all object and cross-referencing information is stored on a BuildEnvironment instance, the domain.data object is also stored in the env.domaindata dict under the key domain.name. Before the build process starts, every active domain is instantiated and given the environment object; the domaindata dict must then either be nonexistent or a dictionary whose ‘version’ key is equal to the domain class’
data_versionattribute. Otherwise, OSError is raised and the pickled environment is discarded.
directive(name: str) → Callable¶
Return a directive adapter class that always gives the registered directive its full name (‘domain:name’) as
get_enumerable_node_type(node: docutils.nodes.Node) → str¶
Get type of enumerable nodes (experimental).
get_full_qualified_name(node: docutils.nodes.Element) → str¶
Return full qualified name for given node.
get_objects() → Iterable[Tuple[str, str, str, str, str, int]]¶
Return an iterable of “object descriptions”.
Object descriptions are tuples with six items:
Fully qualified name.
Name to display when searching/linking.
Object type, a key in
The document where it is to be found.
The anchor name for the object.
How “important” the object is (determines placement in search results). One of:
Default priority (placed before full-text matches).
Object is important (placed before default-priority objects).
Object is unimportant (placed after full-text matches).
Object should not show up in search at all.
get_type_name(type: sphinx.domains.ObjType, primary: bool = False) → str¶
Return full name for given ObjType.
merge_domaindata(docnames: List[str], otherdata: Dict) → None¶
Merge in data regarding docnames from a different domaindata inventory (coming from a subprocess in parallel builds).
process_doc(env: BuildEnvironment, docname: str, document: docutils.nodes.document) → None¶
Process a document after it is read by the environment.
process_field_xref(pnode: sphinx.addnodes.pending_xref) → None¶
Process a pending xref created in a doc field. For example, attach information about the current scope.
resolve_any_xref(env: BuildEnvironment, fromdocname: str, builder: Builder, target: str, node: sphinx.addnodes.pending_xref, contnode: docutils.nodes.Element) → List[Tuple[str, docutils.nodes.Element]]¶
Resolve the pending_xref node with the given target.
The reference comes from an “any” or similar role, which means that we don’t know the type. Otherwise, the arguments are the same as for
The method must return a list (potentially empty) of tuples
('domain:role', newnode), where
'domain:role'is the name of a role that could have created the same reference, e.g.
New in version 1.3.
resolve_xref(env: BuildEnvironment, fromdocname: str, builder: Builder, typ: str, target: str, node: sphinx.addnodes.pending_xref, contnode: docutils.nodes.Element) → docutils.nodes.Element¶
Resolve the pending_xref node with the given typ and target.
This method should return a new node, to replace the xref node, containing the contnode which is the markup content of the cross-reference.
If no resolution can be found, None can be returned; the xref node will then given to the
missing-referenceevent, and if that yields no resolution, replaced by contnode.
The method can also raise
sphinx.environment.NoUrito suppress the
missing-referenceevent being emitted.
role(name: str) → Callable[[str, str, str, int, docutils.parsers.rst.states.Inliner, Dict[str, Any], List[str]], Tuple[List[docutils.nodes.Node], List[docutils.nodes.system_message]]]¶
Return a role adapter function that always gives the registered role its full name (‘domain:name’) as the first argument.
role name -> a warning message if reference is missing
data version, bump this when the format of self.data changes
directive name -> directive class
node_class -> (enum_node_type, title_getter)
a list of Index subclasses
data value for a fresh environment
domain label: longer, more descriptive (used in messages)
domain name: should be short, but unique
type (usually directive) name -> ObjType instance
role name -> role callable
ObjType(lname: str, *roles: Any, **attrs: Any)¶
An ObjType is the description for a type of object that a domain can document. In the object_types attribute of Domain subclasses, object type names are mapped to instances of this class.
lname: localized name of the type (do not include domain name)
roles: all the roles that can refer to an object of this type
attrs: object attributes – currently only “searchprio” is known, which defines the object’s priority in the full-text search index, see
An Index is the description for a domain-specific index. To add an index to a domain, subclass Index, overriding the three name attributes:
name is an identifier used for generating file names. It is also used for a hyperlink target for the index. Therefore, users can refer the index page using
refrole and a string which is combined domain name and
localname is the section title for the index.
shortname is a short name for the index, for use in the relation bar in HTML output. Can be empty to disable entries in the relation bar.
Changed in version 3.0: Index pages can be referred by domain name and index name via
generate(docnames: Iterable[str] = None) → Tuple[List[Tuple[str, List[sphinx.domains.IndexEntry]]], bool]¶
Get entries for the index.
docnamesis given, restrict to entries referring to these docnames.
The return value is a tuple of
A boolean that determines if sub-entries should start collapsed (for output formats that support collapsing sub-entries).
A sequence of
(letter, entries)tuples, where
letteris the “heading” for the given
entries, usually the starting letter, and
entriesis a sequence of single entries. Each entry is a sequence
[name, subtype, docname, anchor, extra, qualifier, descr]. The items in this sequence have the following meaning:
The name of the index entry to be displayed.
The sub-entry related type. One of:
A normal entry.
An entry with sub-entries.
docname where the entry is located.
Anchor for the entry within
Extra info for the entry.
Qualifier for the description.
Description for the entry.
Qualifier and description are not rendered for some output formats such as LaTeX.