Add AutoHeadingAnchorLinks extension #543
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds an extension 'AutoHeadingAnchorLinks' that can be used to automatically add an anchor link to each header.
This is used to generate HTML similar to these examples:
It's a pretty common request for Hugo. I'm personally looking to add this feature to my Hugo site as well.
It's possible to workaround the issue with JavaScript or regex but an extension is a little easier and should be less likely to fail.
When the
AutoHeadingAnchorLinks
andAutoHeadingIDs
extensions are enabled this markdown:...would create this HTML:
It's possible to enable just the
AutoHeadingAnchorLinks
extension without theAutoHeadingIDs
orHeadingIDs
extension, it just generates links like<a href="#">#</a>
. Not that you would want to do that but it doesn't break anything 😁.My only concern with this extension is it seems pretty common to want to use a SVG instead of
#
for the link. It is possible to override this with CSS, i.e.