Skip to content

DOC: Add headers to docstring sections to add link anchors #320

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

Merged
merged 2 commits into from
Apr 19, 2021

Conversation

rossbar
Copy link
Contributor

@rossbar rossbar commented Apr 19, 2021

Closes #317.

Converts the docstring sections enumerated in the style guide to subsection headings, which adds link anchors to each section. Also adds internal references in the style guide to the newly-linkable sections.

@larsoner
Copy link
Collaborator

@larsoner larsoner merged commit b4f2126 into numpy:main Apr 19, 2021
@zmoon
Copy link

zmoon commented Apr 19, 2021

@larsoner it seems like the RTD is not building, due to the default branch name change? Looks like here it still says master.

@jnothman
Copy link
Member

Exciting! But we might want to check the effect on things like TOC... Is numpydoc used in contexts where multiple objects are documented in one page? That would also be a case to check in terms of heading hierarchy. But yes, I'm excited to have heading anchors!

@jnothman
Copy link
Member

What I'd prefer, I'll admit, is an anchor for each parameter... I wonder if that's possible by processing the tree after parsing

@larsoner
Copy link
Collaborator

But we might want to check the effect on things like TOC... Is numpydoc used in contexts where multiple objects are documented in one page?... What I'd prefer, I'll admit, is an anchor for each parameter... I wonder if that's possible by processing the tree after parsing

It sounds like you're talking about having anchors in the docstrings that get processed by NumpyDoc. I thought this, too, when I first read the associated issue and even PR description. But the scope of this is much smaller: it just adds anchors to NumpyDoc's own docs about how to document properly, such as:

https://288-11639513-gh.circle-artifacts.com/0/html/format.html#yields

You can see that the rendered docstring does not have any new anchors:

https://288-11639513-gh.circle-artifacts.com/0/html/example.html

@rossbar rossbar deleted the docstring-section-anchors branch April 20, 2021 06:31
@zmoon zmoon mentioned this pull request Apr 21, 2021
@zmoon
Copy link

zmoon commented Apr 21, 2021

numpydoc/doc/conf.py

Lines 140 to 142 in b4f2126

html_sidebars = {
"**": [],
}

seems to disable the expansion of the ToC headings. I don't know if this is a bug or a feature but it is unfortunate since it makes the improvement here a bit less useful.

Edit: looks like the fix is to replace it by

html_sidebars = {
    "**": ["sidebar-nav-bs.html"],
}

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

Successfully merging this pull request may close these issues.

Anchors for individual sections in numpydoc doc?
5 participants