Skip to main content

toctree_ancestors

Function toctree_ancestors 

Source
pub fn toctree_ancestors(
    toctree_includes: &BTreeMap<String, Vec<String>>,
    docname: &str,
) -> Vec<String>
Expand description

The chain of toctree parents above docname, nearest first, starting with docname itself.

Port of _get_toctree_ancestors (adapters/toctree.py:562-575). A document with no toctree parent has no ancestors at all — not even itself — and the d not in ancestors guard stops the walk on a cycle (which is why this function, unlike _traverse_toctree, survives the circular corpus project).

When a document has several toctree parents the last one wins, matching Sphinx’s parent |= dict.fromkeys(children, p) over toctree_includes. Sphinx iterates that dict in read order and this map iterates in docname order; both resolve to the same “largest parent docname” for the sorted read order every build of this crate performs.