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
Automatically generate anchor tags for all headings? #2690
Comments
Some of the Markdown processors already do this. The only one I know for sure that does it is Redcarpet, but I'm sure there are other ones that do it as well. |
This would have to be done in the markdown processor, or in a post-render hook that parsed the html output and inserted nodes where needed. Kramdown offers the former, nothing that I know of does the latter. I don't think we'd want the latter for core. The JS we use on jekyllrb.com is here http://blog.parkermoore.de/2014/08/01/header-anchor-links-in-vanilla-javascript-for-github-pages-and-jekyll/ |
Great, thank you. |
@kortina kramdown is capable of doing so, but I disabled it (which means it’s on by default):
However as far as I remember correctly, this added ID’s, not |
Some markdown processors (like kramdown & redcarpet) can generate IDs but they typically don't add the anchor icon into your html. There are a few small javascript utilities that can add the anchors also, like AnchorJS (which I wrote) and the jQuery-based anchorific.js. |
Going off @parkr's suggestion, you can do something similar with some jQuery: $('.h2,h3,h4,h5,h6').filter('[id]').each(function () {
$(this).html('<a href="#'+$(this).attr('id')+'">' + $(this).text() + '</a>');
}); |
Is it possible to configure jekyll so that all headings are assigned anchor tags? Eg,
would yield
If this is not a feature, do you think this is something that jekyll users would want and be open to seeing an implementation submitted as a pull request?
The text was updated successfully, but these errors were encountered: