Skip to content

Custom section (header) ID #1141

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

Closed
lo48576 opened this issue Feb 6, 2020 · 4 comments · Fixed by #2013
Closed

Custom section (header) ID #1141

lo48576 opened this issue Feb 6, 2020 · 4 comments · Fixed by #2013
Labels
A-Links Area: Issues with links A-Markdown Area: Issues with markdown

Comments

@lo48576
Copy link

lo48576 commented Feb 6, 2020

It would be useful if the section IDs can be specified manually (such as # About foo {#foo}, supported by many processors including zola).

For example, it would be useful when:

  • Some of section names are very long, but wants IDs to be short enough.
  • Attempt to prevent future link breakage, which can be caused by sections renaming or mdbook algorithm change.
  • Providing multiple sites with different languages, but wants URIs (especially paths and fragments) to be coherent English.

Users can already control paths by setting filename, then it is natural if users can also control fragment part of URIs (/user/specified/path.html#THIS-PART).

Is this feature simply not implemented or considered yet, or are there some reasons to object to this feature?

Maybe related: #880

@ehuss
Copy link
Contributor

ehuss commented Feb 6, 2020

I think such a change would be best made as an extension in pulldown-cmark, the markdown processor mdbook uses. Perhaps ask over there if it would be considered?

I usually just add a tags like <a id="example-fragment"></a> just before the header, but is certainly not ideal.

@ehuss ehuss added A-Links Area: Issues with links A-Markdown Area: Issues with markdown labels Apr 21, 2020
@lo48576
Copy link
Author

lo48576 commented Jan 7, 2022

pulldown-cmark v0.9.0 now has Options::ENABLE_HEADING_ATTRIBUTES extension, which enables users to write custom ID and classes such as # Examples {#examples-foo .example}.

@ImUrX
Copy link
Contributor

ImUrX commented Feb 9, 2023

@ehuss This is easy to work on, should I make this a default option or configurable?

Also I should document it on the mdbook, right?

@ehuss
Copy link
Contributor

ehuss commented Feb 9, 2023

Thanks for taking a look!

I think it should be fine to have it always be on. I think the risk of it causing issues is low.

Just make sure to test that things like the search index work correctly.

And yea, the documentation would be listed as an extension at https://github.com/rust-lang/mdBook/blob/master/guide/src/format/markdown.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Links Area: Issues with links A-Markdown Area: Issues with markdown
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants