autotoctree¶
AutoTocTree Sphinx Directive Implementation
This module implements a custom Sphinx directive .. autotoctree:: that automatically
generates a toctree based on your documentation folder structure. It eliminates the need
to manually update toctree entries when you add or modify documentation sections.
- class docfly.directives.autotoctree.AutoTocTree(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶
Custom Sphinx directive that automatically includes subdirectory index files in a
toctree.This directive works by:
Determining the current document’s location
Finding all subdirectories containing index files
Extracting titles from those index files
Generating a properly formatted toctree directive
The directive supports all standard toctree options (inherited from TocTree) plus additional custom options:
- Parameters:
append_ahead – Flag to append manual entries before the auto-detected entries
index_file – Base name of index files to look for (default: “index”)
Example:
.. autotoctree:: :maxdepth: 1 :index_file: index
- has_content = True¶
May the directive have content?
- option_spec = {'append_ahead': <function flag>, 'caption': <function unchanged_required>, 'class': <function class_option>, 'glob': <function flag>, 'hidden': <function flag>, 'includehidden': <function flag>, 'index_file': <class 'str'>, 'maxdepth': <class 'int'>, 'name': <function unchanged>, 'numbered': <function int_or_nothing>, 'reversed': <function flag>, 'titlesonly': <function flag>}¶
Mapping of option names to validator functions.
- run()[source]¶
Execute the directive to generate the
toctree.This method is called by Sphinx when processing the directive. It creates a docutils node tree representing the
toctree.- Returns:
List of nodes to be inserted into the document
- derive_toctree_rst(current_file: str)[source]¶
Generate the RST content for the
toctreedirective.This method creates a string containing a complete
toctreedirective with entries for all subdirectories with index files.- Parameters:
current_file – Path to the file containing this directive
- Returns:
String containing RST
toctreedirective
Generate the rst content:
.. toctree:: args ... example.rst ...
- Parameters:
current_file
- Returns: