Expand description
Sphinx’s toctree bookkeeping: the read-phase half of
sphinx/environment/collectors/toctree.py plus the two pieces of
sphinx/directives/other.py and sphinx/environment/adapters/toctree.py
that feed it.
Three ports live here, in the order the build runs them:
-
resolve_entries—TocTree.parse_content(directives/other.py:88): turns the directive’s raw content lines into theentries/includefilesattributes of thetoctreenode, resolving relative docnames, expanding:glob:patterns and dropping targets that aren’t real documents. This is environment-dependent (it needs the full docname set), which is why the parser takes afound_docsset: Sphinx resolves at parse time too, fromenv.found_docs. -
build_toc—TocTreeCollector.process_doc(collectors/toctree.py:64): the document’s local table of contents as a doctree-shapedbullet_list, with everytoctreenode copied into it. -
note_toctree—adapters/toctree.py:32: the toctree graph (toctree_includes,files_to_rebuild,glob_toctrees,numbered_toctrees). -
collect_relations/toctree_ancestors/check_consistency— the whole-project reads of that graph (environment/__init__.py:778-823,adapters/toctree.py:562), which only make sense once every document has been noted. -
resolve_toctree—_resolve_toctree(adapters/toctree.py:119): the write-phase expansion of atoctreenode into nested bullet lists, as far as the search index needs it (see its doc comment for what the HTML writer will still have to add).
document_title is the neighbouring TitleCollector.process_doc
(collectors/title.py:27), which shares this module’s
SphinxContentsFilter port.
NOT here (later wave-4 tasks): assign_section_numbers /
assign_figure_numbers (they write toc_secnumbers/toc_fignumbers and
stamp secnumber onto the references this module builds).
Structs§
- Consistency
Message - One diagnostic from
check_consistency, located at a document rather than at a source line (Sphinx passeslocation=docname). - Resolved
Entries toctree['entries'](title, ref) pairs plustoctree['includefiles'].- Toctree
Content - Everything one
toctreedirective needs resolved against the project’s document set — the inputs ofTocTree.parse_content. - Toctree
Warning - One diagnostic produced while resolving a toctree’s entries.
Enums§
- Consistency
Level - Whether a
ConsistencyMessageis a warning (counts toward-W) or an informational note. - Toctree
Warning Kind - What kind of toctree diagnostic this is, kept alongside the Sphinx
message so the builder can map it onto its own coarse
crate::error::WarningType.
Functions§
- build_
toc - The document’s local table of contents (
env.tocs[docname]) and its entry count (env.toc_num_entries[docname]). - check_
consistency - Post-read consistency checks over the finished toctree graph.
- collect_
relations - Every document’s
[parent, prev, next], from a pre-order walk of the toctree graph rooted atenv.root_doc. - docname_
join - Sphinx
docname_join(util/__init__.py):posixpath.normpath(posixpath.join('/' + basedocname, '..', docname))[1:]— a leading/makes the target source-root-relative, anything else is relative to the referencing document’s directory, and./..segments are normalized. - document_
title env.titles[docname]: a freshtitlenode holding the first section title’s contents, filtered exactly like a toc entry’s.- note_
toctree - Record one
toctreenode’s file relations in the environment. - resolve_
entries - Resolve a toctree directive’s content lines against the document set.
- resolve_
toctree - Resolve a
toctreenode into the nested bullet lists Sphinx writes in its place:_resolve_toctree(adapters/toctree.py:119-220) with the arguments the write phase passes for a document’s own toctrees (get_and_resolve_doctree:prune=True, the node’s ownmaxdepth,collapse=False,includehidden=False). - split_
explicit_ title - Split
Some Title <target>into its two halves, as Sphinx’sexplicit_title_re(^(.+?)\s*<(.*?)>$,util/nodes.py) does: the first<that leaves a non-empty title wins, and the line must end with>. A bare<foo>is therefore a literal target named<foo>, not an empty-titled reference. - toctree_
ancestors - The chain of toctree parents above
docname, nearest first, starting withdocnameitself. - toctree_
copies - Every
toctreenode inside a built toc, in the orderbuild_toccopied them in — which is the order Sphinx callsnote_toctreein, since it notes each node at the moment it copies it. - traverse_
toctree - Pre-order depth-first walk of
toctree_includesfromroot, yielding(parent, docname)once per document — the first visit wins.
Type Aliases§
- Relation
[parent, prev, next]— one document’s place in the global document order, asenv.collect_relations()records it.