Skip to content

Add option to maintain case for generated heading ids #7946

@elylucas

Description

@elylucas

Have you read the Contributing Guidelines on issues?

Description

We are migrating from a custom docs implementation to Docusaurus and need to maintain the case consistency of our current headings in our docs for external links currently pointed at our docs.

We thought about using the custom header ids, but we have a lot and it adds a lot of cruft to the md files and will have to added to each new header moving forward to maintain consistency.

It would be nice to have an option specified in docusaurus.config.js that will pass in maintainCase to the github slugger to preserve the casing of the heading anchors.

Has this been requested on Canny?

https://docusaurus.io/feature-requests/p/add-option-to-keep-capitalization-in-generated-heading-ids (older one but pretty much same request)

Motivation

Its been requested before (link in the canny inpuyt), and the answer was the custom header ids. That feature is great for a handful of custom links, but it would be great to turn this option on and it would eliminate the need to have to specify a custom id on each of our headings.

API design

Have a config option named maintainHeaderCasing that will be specified in the config file. This option will need to be passed down and passed as an option to the slugger here:

https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-mdx-loader/src/remark/headings/index.ts#L39

Have you tried building it?

Yes, we've patched it locally for our current needs by hard coding maintainCasing in the options to true here:

https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-mdx-loader/src/remark/headings/index.ts#L39

I'd be willing to contribute a fully working solution passing in the config option as well. I'll just need to figure out how to access the config from here.

Self-service

  • I'd be willing to contribute this feature to Docusaurus myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apprenticeIssues that are good candidates to be handled by a Docusaurus apprentice / traineedomain: markdownRelated to Markdown parsing or syntaxfeatureThis is not a bug or issue with Docusausus, per se. It is a feature request for the future.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions