Skip to content
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

Jekyll+Redcarpet - auto add IDs to headings? #1249

Closed
nottrobin opened this issue Jun 28, 2013 · 8 comments
Closed

Jekyll+Redcarpet - auto add IDs to headings? #1249

nottrobin opened this issue Jun 28, 2013 · 8 comments

Comments

@nottrobin
Copy link

Is there a way with Redcarpet and Jekyll to automatically add IDs to headings?

<h1 id="my-heading">My heading</h1>

I've tried googling lots and lots but haven't found any answer.

@zachgersh
Copy link

Hey @nottrobin,

I believe you would want to do this with liquid and if it were me I would attempt to do it with captures.

You can read more about captures in liquid here:

http://wiki.shopify.com/Logic

@maul-esel
Copy link

See the redcarpet README:

:with_toc_data: add HTML anchors to each header in the output HTML, to allow linking to each section.

This kind of options can be passed via _config.yml.

@nottrobin
Copy link
Author

Thanks @maul-esel I didn't know about that - I think that's the best solution. Ideally the IDs would be more semantic (e.g. my-heading rather than toc_0), but this solution will do.

For anyone else with the same problem, I added it onto my _config.yml as follows:

markdown: redcarpet
redcarpet:
    extensions: [with_toc_data]

If anyone did want to implement a more semantic solution, I imagine one should start with editing the html.c file in the Sundown project.

@iloveip
Copy link

iloveip commented Apr 13, 2014

Hi @nottrobin
Do you have any idea where such edited html.c file should be saved? Do I have to put a link to it anywhere for it to be recognized by Redcarpet?
I would like to simply get rid of toc_ in my IDs and start them with 1 instead of 0. So I guess the only way is to edit this file, as you've said. But when I simply save it in my root folder it doesn't seem to work.

shospodarets added a commit to shospodarets/shospodarets.github.io that referenced this issue Mar 17, 2015
@lengerfulluse
Copy link

Sorry for reopen this thread.
Hi @maul-esel
I have a similar question for using rdiscount to generate toc: I configure rdiscount with:

markdown: rdiscount
rdiscount:
    extensions:
        - generate_toc

And rdiscount auto add id for headers. But, unfortunately it generates the same id for all headers, which makes all the toc items point to the same anchor. Do you have some ideas about it? Thanks in advance!

@maul-esel
Copy link

no idea sorry 😞

@parkr
Copy link
Member

parkr commented Jul 27, 2015

@lengerfulluse Please bring that up with the Rdiscount folks: https://github.com/davidfstr/rdiscount/issues

👋 @maul-esel, long time no see!

@lengerfulluse
Copy link

Thanks @parkr, I just submit a new issue: davidfstr/rdiscount#129. Will keep this thread close.

@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants