htmljekyllkramdown

Jekyll link within page


I'm using Jekyll on Github, and I wonder whether there's a way to link to a section within a page. Say I have a section like

## Section 1 ##
section content 

and later in the same page I want to link to this section. I've found how to link to another page within the blog and do footnotes, but not this.

As a note, I use markdown: kramdown in my _config.yml


Solution

  • kramdown supports the automatic generation of header IDs if the option auto_ids is set to true (which is the default). This is done by converting the untransformed, i.e. plain, header text

    So in the above example ## Section 1 ##, it would generate the following id: id="section-1", then the anchor is linked to via the A element:

    <A href="#section-1">Section One</A>
    

    Or in plain kramdown/markdown: [Section 1](#section-1)