sphinx-doc / sphinx-doc/sphinx
Add toc entry autofunction
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Is your feature request related to a problem? Please describe.
Goal
I would like to add a toc entry to each .. autofunction:
Suppose:
.. automodule:: foo.bar
.. rubric:: Functions
.. autosummary::
myfunction
otherfunction
.. rubric:: Details
.. autofunction:: myfunction
.. autofunction:: otherfunction
Now I would like to add a TOC entry for each autofunction.
Background
To simplify the navigation, I would like to customise autodoc a bit, but still keep things automatic.
I am using
.. currentmodule:: foo
.. autosummary::
:toctree: generated
bar
Together with a template _templates/autosummary/module.rst
.. This file is automatically generated
{{ name | escape | underline }}
.. automodule:: {{ fullname }}
{% block functions %}
{% if functions %}
.. rubric:: {{ _('Functions') }}
.. autosummary::
{% for item in functions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
.. rubric:: {{ _('Details') }}
{% if functions %}
{% for item in functions %}
.. autofunction:: {{ item }}
{%- endfor %}
{% endif %}
{% block modules %}
{% if modules %}
.. rubric:: Modules
.. autosummary::
:toctree:
:recursive:
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
which generates `generated/foo.bar.rst
bar
===
.. automodule:: foo.bar
.. rubric:: Functions
.. autosummary::
myfunction
otherfunction
.. rubric:: Details
.. autofunction:: myfunction
.. autofunction:: otherfunction
Now I would like to add a toc entry for each autofunction to help navigation.
Vaguely related to https://github.com/sphinx-doc/sphinx/issues/6316
Describe the solution you'd like
For example an option
.. autofunction:: myfunction
:toc-entry: 2
(with the entry level)
Describe alternatives you've considered
This seems to be all taken care of when one uses .. automodule:, so somewhere that should be an option to enable such behaviour.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated generated/foo.bar.rst example and the _templates/autosummary/module.rst template shown in the issue. Trace how the autofunction directives are produced and determine how the proposed :toc-entry: level should affect navigation. Done means each configured autofunction produces the requested TOC entry without disrupting the existing autosummary and automodule output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100