-
Notifications
You must be signed in to change notification settings - Fork 30
Add support for custom heading anchors in Markdown. #153
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
Conversation
Custom heading anchors allow more control over anchor names in generated HTML. Inline annotations can now define specific anchors, and normalization ensures consistent formatting. Updated relevant tests, documentation, and rendering logic to support this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about using curly braces instead of square brackets?
I think curly braces are less likely to be part of a heading.
Kramdown has a similar approach.
They use this:
Hello {#id}
-----
# Hello {#id}
# Hello # {#id}
Source: https://kramdown.gettalong.org/syntax.html#specifying-a-header-id
IMO, Kramdown also cleverly utilizes the #
, which makes it even less likely to be part of the heading.
TL;DR
I would suggest either
I prefer this because it seems to be an existing convention across other markdown flavours
# Heading {#id}
or
# Heading [#id]
I personally prefer It will also be easier to disambiguate variable substitutions and these anchors. A more technical reason I'm not thrilled about brackets is that markdig has an extension to attach arbitrary data to elements using brackets at the end. We don't use that today but we might in the future. Want to leave that door open |
Understood. What do you think about the Semantically, this also resembles an URL fragment, making it clearer that this will be the ID of the element. I understand that it's not very likely. But there is still a possibility that someone wants to create a header like: # Heading [Part of the heading] And the the |
Technically that is supported today, we can make it
I'm leaning to making this a suggestion then, what do you tink @reakaleek ? |
Co-authored-by: Jan Calanog <jan.calanog@elastic.co>
I've updated the docs to use |
SGTM. Thank you |
Custom heading anchors allow more control over anchor names in generated HTML. Inline annotations can now define specific anchors, and normalization ensures consistent formatting. Updated relevant tests, documentation, and rendering logic to support this feature.
You can now override the autogenerated anchors for headings with
## My header [my-completely-different-anchor]
Updated the syntax guide to document this new feature.
This also addresses the bugs reported in #125