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

Custom titles do not work if a page has multiple H1 headers #1078

Closed
choldgraf opened this issue Dec 12, 2022 · 12 comments
Closed

Custom titles do not work if a page has multiple H1 headers #1078

choldgraf opened this issue Dec 12, 2022 · 12 comments
Labels
kind: bug Something isn't working

Comments

@choldgraf
Copy link
Collaborator

choldgraf commented Dec 12, 2022

If there are multiple H1 headers on a page (e.g., multiple # Single hash headers), then title over-rides that are specified in .. toctree:: objects do not work properly.

To reproduce

  • Create a page with multiple H1 titles (e.g. mypage.md with # My title and # My H1 title section).

  • In a parent page, link it with a toctree like:

    .. toctree::
      
      My custom title page <mypage>
    

And the title should not be over-ridden properly.

Originally reported in:

@trallard
Copy link
Collaborator

trallard commented Jan 12, 2023

This is an interesting one - I wonder if this is a decision made at the Sphinx level.
Some things to consider:

  1. From an author's point of view, it might be helpful to have more than one H1 heading in a document/web page - and from a web development perspective, this is possible (a.k.a, nothing is preventing this from doing it)
  2. From an accessibility point of view, headings (and heading hierarchy) help screen readers navigate the document. So one should not have more than one H1 in a given document (I can find some resources - there is nothing formal like a criterion or rule that says it has to be this way but the consensus in the accessibility community is that there should be one and only one H1 heading

So based on point 2. I wonder if somewhere in Sphinx this was made as a conscious decision to only have one H1 header shown in the TOC

@choldgraf
Copy link
Collaborator Author

Yes I think that is basically it - the first header level is special and reserved for the title. All other headers are expected to be nested under it. If you add multiple top level headers, sphinx treats them as if they were different pages entirely. That's what messes up the TOC and sidebar stuff.

I guess the question is whether we should be clever here and basically say "if there is more than one top level header then nest all subsequent headers under the first".

The other thing that could be done is to support "title:" in the page metadata, and if that exists then nest the page content under a top level header of that name.

@12rambau
Copy link
Collaborator

as explained by @choldgraf Sphinx is treating each level 1 header as defining a new page in the toctree hence the confusion when there are multiple.

The thing to keep in mind when using Sphinx is that it is designed for many other build type, not only HTML. In a Latex build, multiplying h1 level will lead to a very strange paginaltion of your document (same for ebooks). I think that's also why it's by design not suported.

@choldgraf

This comment was marked as off-topic.

@12rambau

This comment was marked as off-topic.

@choldgraf

This comment was marked as off-topic.

@choldgraf
Copy link
Collaborator Author

I think the simplest thing to recommend would be to add a quick check for whether there are multiple top level sections in the page, and emit a warning to tell people to nest all headers under one title header

@trallard
Copy link
Collaborator

I think the simplest thing to recommend would be to add a quick check for whether there are multiple top-level sections in the page, and emit a warning to tell people to nest all headers under one title header

Yup - I would prefer avoiding adding workarounds to an intentional design decision that also happens to help with our accessibility goals. And instead, encourage folks to use only one H1 header.

@trallard
Copy link
Collaborator

@choldgraf - since it seems we decided not to create a workaround due to accessibility concerns and potential issues with other output types (i.e. LateX), can we close this issue with not planned and open a follow-up one with the checks discussed in this comment plus some guidance on the docs on why using multiple H1 headers is discouraged from an accessibility POV?

@12rambau
Copy link
Collaborator

I would simply leave this one open and reference/close it in/with the documentation update you want to make.

@drammock
Copy link
Collaborator

superseded by #1351. @12rambau I opted to create a new issue in order to distill just the relevant info so that it's clearer from the title/description what the fix should be (hopefully making it easier for non-core-team contributors to fix it)

@drammock drammock closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2023
@12rambau
Copy link
Collaborator

fair enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants