Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a ToC entry for every function, method, class, etc #6316

Closed
Phillip-M-Feldman opened this issue Apr 22, 2019 · 63 comments · Fixed by #10807
Closed

Create a ToC entry for every function, method, class, etc #6316

Phillip-M-Feldman opened this issue Apr 22, 2019 · 63 comments · Fixed by #10807
Assignees
Labels
Milestone

Comments

@Phillip-M-Feldman
Copy link

It would be useful to have an option that causes Sphinx to automatically create a TOC entry for every function, class, and method. (In the absence of this, tables of contents are of limited value).

@Phillip-M-Feldman Phillip-M-Feldman added the type:enhancement enhance or introduce a new feature label Apr 22, 2019
@Phillip-M-Feldman
Copy link
Author

I will try to make this enhancement, but am hoping that someone can point me to the right place in the code.

@Phillip-M-Feldman
Copy link
Author

What is the target date for the 3.0.0 milestone?

@tk0miya
Copy link
Member

tk0miya commented Jun 9, 2019

3.0 will be released in next spring.

@pawamoy
Copy link

pawamoy commented Dec 9, 2019

@Phillip-M-Feldman are you still planning to work on this? @tk0miya you added this issue to the 3.0.0 milestone: are you going to implement it?

@Phillip-M-Feldman
Copy link
Author

Phillip-M-Feldman commented Dec 9, 2019 via email

@pawamoy
Copy link

pawamoy commented Dec 12, 2019

I'm currently writing a plugin for mkdocs with this functionality anyway 🙂

@tk0miya
Copy link
Member

tk0miya commented Dec 14, 2019

No, I don't have time for developing 3.0. At present, I'm doing my best to 2.x release.

@Phillip-M-Feldman
Copy link
Author

What is the relationship (if any) between mkdocs and Sphinx?

Also: I have some time to work this issue, but still need pointers re. where to look in the code.

P.S. I'm surprised that this functionality wasn't built into Sphinx from the start.

@pawamoy
Copy link

pawamoy commented Aug 17, 2020

Sphinx and MkDocs both are static site generators if I may say? MkDocs is language agnostic and uses Markdown natively. Other than that there's no relation between the two.

@Phillip-M-Feldman
Copy link
Author

Phillip-M-Feldman commented Aug 18, 2020 via email

@alexisrolland
Copy link

I'm voting up for this feature. It seems essential to me.

@AA-Turner
Copy link
Member

Sphinx 5.2.0 has been released incorporating this feature.

A

tony added a commit to vcs-python/libvcs that referenced this issue Sep 24, 2022
@tony
Copy link
Contributor

tony commented Sep 24, 2022

@AA-Turner Looks good, thank you!

Settings options:

  • add_function_parentheses = False (default: True)
  • toc_object_entries_show_parents can be (default: 'domain'):
    • toc_object_entries_show_parents = 'domain'
    • toc_object_entries_show_parents = 'hide'
    • toc_object_entries_show_parents = 'all'
Example on Sphinx 5.2 w/ Furo theme (screenshot)

My settings:

toc_object_entries_show_parents = 'hide'

URL: https://libvcs.git-pull.com/sync/git.html (may break in future, sorry!)

image

image

@josephmure
Copy link

Is it possible to disable this feature? It messes up the rendering of a project I work on:

https://openturns.github.io/openturns/master/user_manual/_generated/openturns.ConditionalDistribution.html

image

Here is how it normally looks:

https://openturns.github.io/openturns/1.19/user_manual/_generated/openturns.ConditionalDistribution.html

image

Using the hide option makes it a little better, but does not restore the old look:

image

@AA-Turner
Copy link
Member

What theme are you using? I'd suggest this is more a theme error with not handling long ToC entries -- a horizontal scrollbar would be more useful here.

A

@pradyunsg
Copy link
Contributor

You can also set toc_object_entries_show_parents = 'hide' if you’d prefer to have shorter names.

@jakobandersen
Copy link
Contributor

You can also set toc_object_entries_show_parents = 'hide' if you’d prefer to have shorter names.

Wait, you can't disable this in any way? That prevents people from upgrading Sphinx unless they redesign their document structures. That sounds like a breaking change that can not happen in a minor release.

@pradyunsg
Copy link
Contributor

pradyunsg commented Sep 28, 2022

It's a new feature, which is why it's been added in a new minor version release. I'll point you to an excellent blog post, that I request you read in full.

Whether adding sidebar content when certain themes that don't do the bare-minimum of text wrapping in the sidebars is backwards-incompatible is... well, that's a discussion I'm not going to be a party in. :)

@schtandard
Copy link

Leaving aside the question of minor/major versions: I was also under the assumption that this would be an optional feature, not a mandatory one. I expect many, many people to be unpleasently surprised if they cannot turn it off.

Is there any reason not to have the old behavior be the default and the new feature be an option?

@asmeurer
Copy link
Contributor

asmeurer commented Sep 28, 2022

I believe reasoning was that we shouldn't add a configuration option for something unless we actually know there will be people who want to turn it off. No one up til now has requested that. I do sort of agree that a theme not handling wrapping isn't a great reason to turn this off (no doubt that can be fixed with a simple CSS change). Such a theme also won't handle a normal header with a long title properly either. Do you have another reason to want to disable it? The only one I can think of is if you already manually added toc entries for each autodoc entry, making this redundant.

I personally think it's fine to make this disableable, but also feel it should continue to be on by default because it's a nice feature for the majority of use cases. A feature that is off by default will only be used by a very small fraction of people who notice the option and turn it on. Sphinx already has too many of these "off by default" nice features IMO.

@AA-Turner
Copy link
Member

Disabling the feature currently is not supported. A PR to add support would be considered, but the default would remain as current (domain objects in the table of contents).

As a workaround to disable support, you can patch the _toc_entry_name method in your extension or conf.py (untested):

PyObject._toc_entry_name = lamba signode: ''

A

@josephmure
Copy link

What theme are you using? I'd suggest this is more a theme error with not handling long ToC entries --

A custom version of the "sphinxdoc" theme, but I get the same problem with the vanilla "classic" theme (see picture below).

a horizontal scrollbar would be more useful here.

If a horizontal scrollbar is needed to actually see the method name, most users will not bother and will rather search through the main page rather than the sidebar.

You can also set toc_object_entries_show_parents = 'hide' if you’d prefer to have shorter names.

I am aware of this. Although using it can avoid the rendering error if method names are not too long, I would prefer not to have method names in the ToC at all because they are redundant: there is already a method list in the page (see picture below).

Whether adding sidebar content when certain themes that don't do the bare-minimum of text wrapping in the sidebars is backwards-incompatible is... well, that's a discussion I'm not going to be a party in. :)

The problem does not seem to be text wrapping in general: as you can see in the picture below, the class name itself is also long, but gets wrapped. Only method names (perhaps because of the particular font that is used) are not.

image

As a workaround to disable support, you can patch the _toc_entry_name method in your extension or conf.py (untested):

PyObject._toc_entry_name = lamba signode: ''

I do not understand this line. What should I add in conf.py exactly?

@jakobandersen
Copy link
Contributor

It is indeed a feature, but it fundamentally changes the structure of documents compiled with it. From the perspective of a user that has designed their document without this feature in mind (implicitly that's all Sphinx < 5.2 users), it is breaking their document.
The hackish workaround is fine for now, but there really should be a proper option. That is, at least I request this feature.

@AA-Turner
Copy link
Member

Please see #10886 (intended for 5.2.3) for an option for global control and a new nocontentsentry flag (as requested by @jakobandersen)

A

yoda-vid added a commit to sanderslab/magellanmapper that referenced this issue Oct 11, 2022
Use the Furo theme, which provides a minimalist and yet modern interface, including light/dark color support and the new table of contents entries for API docs (see sphinx-doc/sphinx#6316).

- Change theme to Furo
- Install `furo` in the `docs` group
- Fix missing language configuration
- Turn off sidebar customization to use Furo default sidebars instead
- Add API docs link to main sidebar
yoda-vid added a commit to sanderslab/magellanmapper that referenced this issue Oct 12, 2022
Use the Furo theme, which provides a minimalist and yet modern interface, including light/dark color support and the new table of contents entries for API docs (see sphinx-doc/sphinx#6316).

- Change theme to Furo
- Install `furo` in the `docs` group
- Fix missing language configuration
- Turn off sidebar customization to use Furo default sidebars instead
- Add API docs link to main sidebar
@AA11BB22
Copy link

Can be this feature be extended to support other domains (non-Python domains ... namely C++ domain)?

@hagenw
Copy link

hagenw commented Oct 21, 2022

image

The problem does not seem to be text wrapping in general: as you can see in the picture below, the class name itself is also long, but gets wrapped. Only method names (perhaps because of the particular font that is used) are not.

The text for the main heading gets wrapped because it is text whereas the new entries are added as <code></code> to the TOC which provides prevents wrapping in most themes and can also lead to strange font sizes, e.g.

image

Another problem is that a lot of users have started to add headings to the docs as the new TOC feature was missing for years and also to have a better separation on the page:

image

With the new feature you have the entries repeated in the TOC, one for the heading and one for the code entry as is present in both examples shown here.

So it's indeed a relative big change and should have an option to disable it as it now has since version 5.2.3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.