Can sphinx auto generate a table of contents from all anchors on a page?

Viewed 176

I'm trying to use the breathe plugin which is super limited out of the box: https://github.com/michaeljones/breathe

It has this directive that generates a big dump of all classes/interfaces/etc and just puts them on the same page: doxygenindex.

While it generates an anchor on the page for every class/interface/etc it has no features for generating a table of contents.

Does sphinx itself have a way generating a toc from every anchor on a page? I think that would be enough for me. Having it all on one page is nice for ctrl+f, but having a toc as well would improve discoverability for users unfamiliar with the codebase.

Edit

There is a very old GitHub issue for this, maybe this feature has already been added? Or if it's still not possible maybe it is with some plugin: https://github.com/sphinx-doc/sphinx/issues/2954

Edit

Per suggestion using .. contents:: like this does not appear to do anything. I see no toc generated for the page, but maybe I'm not understanding how to use it?

Some page
---------

.. contents:: Table of contents
    :local:
    :backlinks: entry
    :depth: 2

.. doxygenindex::
   :project: myproject
1 Answers

Does the contents directive do what you want?

The "contents" directive generates a table of contents (TOC) in a topic. Topics, and therefore tables of contents, may occur anywhere a section or transition may occur. Body elements and topics may not contain tables of contents.

Here's the directive in its simplest form:

.. contents::

Try the below sample online.

=====
Title
=====

.. contents:: Table of contents
    :local:
    :backlinks: entry
    :depth: 2


Heading
-------

Paragraph

Subheading
^^^^^^^^^^

Paragraph

Subsubheading
#############

Paragraph

Demo

Related