Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make classes appear on TOC in Sphinx

I'm starting to document a few python classes using ext.autodoc. I have several *.rst files with content such as

========
mymodule
========

.. automodule:: mymodule
   .. autoclass:: myclassA
       :members:
   .. autoclass:: myclassB
       :members:

plus an index.rst:

.. toctree::
   :maxdepth: 2
   mymodule

'mymodule' shown in the table of contents, but I'd also like to see the classes in the TOC too:

  • mymodule
    • myclassA
    • myclassB

How can I make sphinx create something like a section for each class? Or is there a good reason not to do so?

thanks

like image 843
Stefan Avatar asked Jul 21 '13 14:07

Stefan


1 Answers

Sphinx cannot create sections. You'll have to add them yourself in the .rst file. Something like this:

myclassA
--------

.. autoclass:: myclassA
   :members:

myclassB
--------

.. autoclass:: myclassB
   :members:

For some alternative suggestions that might be interesting, see these questions (and the answers):

  • Sphinx customizing autoclass output
  • Sorting display by class using sphinx with 'autodoc'?
like image 53
mzjn Avatar answered Sep 21 '22 16:09

mzjn