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

Support Level 1 title (H1) in table of contents #11041

Open
1 of 2 tasks
ben-qnimble opened this issue Mar 28, 2025 · 4 comments
Open
1 of 2 tasks

Support Level 1 title (H1) in table of contents #11041

ben-qnimble opened this issue Mar 28, 2025 · 4 comments
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers

Comments

@ben-qnimble
Copy link
Contributor

Have you read the Contributing Guidelines on issues?

Description

Currently, the setting toc_min_heading_level must be set to 2 or greater. In some markdown documents, it would be nice to a table of contents that includes level 1 (h1) titles. For example:

---
hide_title: true
---

# Part 1

## Part 1a

## Part 1b

# Part 2

## Part 2a

The default setting of toc_min_heading_level=2 could be left unchanged, so this would have no effect any current setups (validation prevents trying to set toc_min_headiner_level=1). But it would enable the option to have a table of contents use level one headers as desired.

Has this been requested on Canny?

No response

Motivation

I often use level 1 titles on my markdown documents and it would be nice for them to be able to be included in the TOC.

API design

No response

Have you tried building it?

I took a quick pass and changed the validation to allow for setting toc_min_heading_level=1 but it didn't change the generated table of contents. I poked around at packages/docusaurus-theme-common/src/utils/tocUtils.ts and it seemed like it should work for a min of 1 as well as higher, but that's as far as I got.

Self-service

  • I'd be willing to contribute this feature to Docusaurus myself.
@ben-qnimble ben-qnimble added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers labels Mar 28, 2025
@Josh-Cena
Copy link
Collaborator

Why do you want multiple H1s? The first H1 is always going to be different from subsequent H1s because it will be used as page title, sidebar label, etc. so you are just inviting for more inconsistencies. This is a practice explicitly discouraged by both HTML and Markdown linters.

@ben-qnimble
Copy link
Contributor Author

I don't think it is fair to say that the first h1 will always be used as the title and sidebar, etc. There are options (title, sidebar_label) for setting them independently. When using those options, having only a single H1 no longer is the only reasonable structure. For example:

---
title: Pets
sibebar_label: Pets
hide_title: true
---

# Dogs
Dogs are great ...

# Cats
But so are Cats

@ben-qnimble
Copy link
Contributor Author

That said, if multiple H1 is discouraged by your HTML / Markdown linters this is no longer a small request to expand the allowed range of values on parameter. I think it might make sense to document somewhere that it is recommended to only have one level 1 title in Markdown (all?) pages.

@slorber
Copy link
Collaborator

slorber commented Mar 31, 2025

Multiple HTML h1 on the same page is considered a bad practice: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements#avoid_using_multiple_h1_elements_on_one_page

We don't really need to document that, it's not Docusaurus specific

Markdown documents can contain more than 1 #, and either this is a good idea or not is plugin-specific.

For example if you build a slide deck using Markdown and --- separators for slides, it's fine to use one # per --- delimited section.

Docusaurus core plugins all produce a single HTML page from a single document so the HTML good practice applies here, and similarly, you should avoid using more than one #. But it doesn't mean third-party plugin authors can't implement a system where a single Markdown input produces multiple pages, similar to our slide deck example above.

So, we don't really want to document good/bad practices that are not so dogmatic and plugin-specific. It's not Docusaurus responsibility to teach you cross-cutting concerns such as HTML good practices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers
Projects
None yet
Development

No branches or pull requests

3 participants