ドメインAPI¶
- class sphinx.domains.Domain(env: BuildEnvironment)[ソース]¶
ドメインというのは、似たような特性を持つオブジェクトごとに用意された「オブジェクト」説明ディレクティブと、それらに対応してリファレンスを作成するロールを集めたものです。例えば、Pythonのモジュール、クラス、関数、テンプレート言語であればエレメント、Sphinxであればロールとディレクティブなどです。
ドメインごとに、既存のオブジェクトの情報や、それらへの参照の仕方などを個別の領域に保存します。保存先は self.data で、辞書でなければなりません。また、Sphinxの一部として決まったフォーマットでオブジェクトの情報を公開するための関数や、ユーザが参照できるようにしたり、ドメインごとの方法でオブジェクトを探索する関数をいくつか実装する必要があります。
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) type[Directive] | None[ソース]¶
self.nameで指定されたドメイン付きで、完全な名前('ドメイン:名前')で登録されたディレクティブ を与える、ディレクティブアダプタークラスを返します。
- get_objects() Iterable[tuple[str, str, str, str, str, int]][ソース]¶
Return an iterable of "object descriptions".
Object descriptions are tuples with six items:
nameFully qualified name.
dispnameName to display when searching/linking.
typeObject type, a key in
self.object_types.docnameThe document where it is to be found.
anchorThe anchor name for the object.
priorityHow "important" the object is (determines placement in search results). One of:
1Default priority (placed before full-text matches).
0Object is important (placed before default-priority objects).
2Object is unimportant (placed after full-text matches).
-1Object should not show up in search at all.
- merge_domaindata(docnames: Set[str], otherdata: dict[str, Any]) 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: nodes.document) None[ソース]¶
ドキュメントが環境によって読まれた後で、そのドキュメントを処理します。
- process_field_xref(pnode: 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: pending_xref, contnode: Element) list[tuple[str, nodes.reference]][ソース]¶
target を持つ、
pending_xref(未解決のクロスリファレンス) node の参照先の解決を行います。"any", もしくはそれに類似するロールに基づくリファレンスは、タイプがわからないということを意味します。もしくは、引数が
resolve_xref()と同様のものであるかです。このメソッドはタプルを要素に持つリストを返す必要があります(リストは空の可能性があります)。各要素はタプルで、
('domain:role', newnode)の形式です。'domain:role'は'py:func'のようなnewnodeを生成するときに使われるロール名で、newnodeはresolve_xref()の返値と同じです。Added in version 1.3.
- resolve_xref(env: BuildEnvironment, fromdocname: str, builder: Builder, typ: str, target: str, node: pending_xref, contnode: Element) nodes.reference | None[ソース]¶
typ 型と、 target を持つ、
pending_xref(未解決のクロスリファレンス) node の参照先の解決を行います。このメソッドは、xrefノードと置き換えるための、新しいノードを返さなければなりません。また、この新しいノードには、クロスリファレンスのマークアップのコンテンツである、 contnode を含めます。
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 themissing-referenceevent being emitted.
- class sphinx.domains.ObjType(lname: str, /, *roles: Any, **attrs: Any)[ソース]¶
ObjTypeは、そのドメインでドキュメントを書くことができる、オブジェクトの種類に対する説明ユニットです。Domainのサブクラスの object_types の辞書の中に、オブジェクト名と、このクラスのインスタンスのマッピングが保持されます。
コンストラクタ引数
lname: ローカライズされた型名
roles: この型を参照できる、すべてのロール
attrs: オブジェクトの属性。現在では、全文検索インデックス内での、オブジェクトの優先順位(
Domain.get_objects()参照)のみが定義されています。
- class sphinx.domains.Index(domain: Domain)[ソース]¶
Indexは、ドメインに特化した索引のための説明を行うクラスです。ドメインに対する索引を追加する場合には、Indexのサブクラスを作り、3つの名前属性をオーバーライドします:
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 andnameattribute (ex.:ref:`py-modindex`).localname は索引のセクションタイトルです。
shortname は索引に対する短い名前です。これは、HTML出力のリレーションバーで使用されます。もしも空であれば、リレーションバーのエントリーは無効化されます。
and providing a
generate()method. Then, add the index class to your domain's indices list. Extensions can add indices to existing domains usingadd_index_to_domain().バージョン 3.0 で変更: Index pages can be referred by domain name and index name via
refrole.- abstractmethod generate(docnames: Iterable[str] | None = None) tuple[list[tuple[str, list[IndexEntry]]], bool][ソース]¶
Get entries for the index.
If
docnamesis given, restrict to entries referring to these docnames.The return value is a tuple of
(content, collapse):collapseA boolean that determines if sub-entries should start collapsed (for output formats that support collapsing sub-entries).
content:A sequence of
(letter, entries)tuples, whereletteris the "heading" for the givenentries, usually the starting letter, andentriesis a sequence of single entries. Each entry is anIndexEntry.
- class sphinx.domains.IndexEntry(name: str, subtype: int, docname: str, anchor: str, extra: str, qualifier: str, descr: str)[ソース]¶
An index entry.
注釈
The qualifier and description are not rendered for some output formats, such as LaTeX.
- class sphinx.directives.ObjectDescription(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[ソース]¶
Directive to describe a class, function or similar object.
Not used directly, but subclassed (in domain-specific directives) to add custom behaviour.
- _object_hierarchy_parts(sig_node: desc_signature) tuple[str, ...][ソース]¶
Returns a tuple of strings, one entry for each part of the object's hierarchy (e.g.
('module', 'submodule', 'Class', 'method')). The returned tuple is used to properly nest children within parents in the table of contents, and can also be used within the_toc_entry_name()method.This method must not be used outwith table of contents generation.
- _toc_entry_name(sig_node: desc_signature) str[ソース]¶
Returns the text of the table of contents entry for the object.
This function is called once, in
run(), to set the name for the table of contents entry (a special attribute_toc_nameis set on the object node, later used inenvironment.collectors.toctree.TocTreeCollector.process_doc().build_toc()when the table of contents entries are collected).To support table of contents entries for their objects, domains must override this method, also respecting the configuration setting
toc_object_entries_show_parents. Domains must also override_object_hierarchy_parts(), with one (string) entry for each part of the object's hierarchy. The result of this method is set on the signature node, and can be accessed assig_node['_toc_parts']for use within this method. The resulting tuple is also used to properly nest children within parents in the table of contents.An example implementations of this method is within the python domain (
PyObject._toc_entry_name()). The python domain sets the_toc_partsattribute within thehandle_signature()method.
- add_target_and_index(name: ObjDescT, sig: str, signode: desc_signature) None[ソース]¶
Add cross-reference IDs and entries to self.indexnode, if applicable.
name is whatever
handle_signature()returned.
- after_content() None[ソース]¶
Called after parsing content.
Used to reset information about the current directive context on the build environment.
- before_content() None[ソース]¶
Called before parsing content.
Used to set information about the current directive context on the build environment.
- get_signatures() list[str][ソース]¶
Retrieve the signatures to document from the directive arguments.
By default, signatures are given as arguments, one per line.
- handle_signature(sig: str, signode: desc_signature) ObjDescT[ソース]¶
Parse the signature sig.
The individual nodes are then appended to signode. If ValueError is raised, parsing is aborted and the whole sig is put into a single desc_name node.
The return value should be a value that identifies the object. It is passed to
add_target_and_index()unchanged, and otherwise only used to skip duplicates.
- run() list[Node][ソース]¶
Main directive entry function, called by docutils upon encountering the directive.
This directive is meant to be quite easily subclassable, so it delegates to several additional methods. What it does:
find out if called as a domain-specific directive, set self.domain
create a desc node to fit all description inside
parse standard options, currently no-index
create an index node if needed as self.indexnode
parse all given signatures (as returned by self.get_signatures()) using self.handle_signature(), which should either return a name or raise ValueError
add index entries using self.add_target_and_index()
parse the content and handle doc fields in it
- transform_content(content_node: desc_content) None[ソース]¶
Can be used to manipulate the content.
Called after creating the content through nested parsing, but before the
object-description-transformevent is emitted, and before the info-fields are transformed.
- final_argument_whitespace = True¶
May the final argument contain whitespace?
- has_content = True¶
May the directive have content?
- option_spec: ClassVar[OptionSpec] = {'no-contents-entry': <function flag>, 'no-index': <function flag>, 'no-index-entry': <function flag>, 'no-typesetting': <function flag>, 'nocontentsentry': <function flag>, 'noindex': <function flag>, 'noindexentry': <function flag>}¶
Mapping of option names to validator functions.
- optional_arguments = 0¶
Number of optional arguments after the required arguments.
- required_arguments = 1¶
Number of required directive arguments.