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

handling the case of multiple top-level headers #108

Closed
wants to merge 1 commit into from

Conversation

choldgraf
Copy link
Collaborator

I ran into a weird bug - if you have a page with multiple top-level headers, then the in-page TOC logic breaks down.

This is less-common (though possible) with rST, but consider in markdown a page like this:

My title
========

# My header 1

Content 1

# My header 2

Content 2

In this case, Sphinx will parse all of the headers at the same, top level. Our in-page TOC code assumes that the only top-level header is the title node, and that all other headers are underneath it.

This PR does the following:

  • Check if there is more than 1 entry in the TOC object. If so, it means there is more than 1 header at the top level.
  • Assume that the non-title top-level headers are the "true" headers for the document
  • In the Jinja step, take the non-title top-level headers, and append them to the title's top-level header, so that we can render

The one awkward thing is that if there are other 2nd and 3rd level headers in-between the next 1st-level header, they will be missed in the TOC. Something like this:

My title
========

## My second level

# My header 1

Content 1

# My header 2

Content 2

The TOC would only show "My header 1" and "My header 2".

But I think that's probably the behavior we'd want to encourage?

Lemme know if you'd like me to explain a bit more...I think the longer-term solution will be to make the "get_page_toc" function a little bit less-hacky, but this seems like a reasonable patch for now

@jorisvandenbossche
Copy link
Member

@choldgraf Can you rebase this? Or do you directly want to do a different solution as described in #197 ?

@choldgraf
Copy link
Collaborator Author

closing in favor of #199

@choldgraf choldgraf closed this Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants