Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 233
user7843034 Avatar asked Apr 26 '17 07:04

user7843034


People also ask

How do you link pages on Jekyll?

Like posts, pages can be linked to in multiple ways: Reference the page's full root-relative URL e.g., /about. html . Use Jekyll's {% link %} tag.

Can you hyperlink in markdown?

Markdown syntax for a hyperlink is square brackets followed by parentheses. The square brackets hold the text, the parentheses hold the link.

What is the URL of Jekyll?

When you run jekyll serve , Jekyll will build your site with the value of the host , port , and SSL-related options. This defaults to url: http://localhost:4000 .

What is markdown in Jekyll?

Markdown is a language used to simplify writing HTML. Plain text characters like # and * are used in place of HTML tags. These characters are then processed by Jekyll (or another script or application) and transformed into HTML tags. As the name Markdown suggests, the language has been trimmed down to a minimum.


2 Answers

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)

like image 79
marcanuy Avatar answered Sep 27 '22 19:09

marcanuy


It seems that this has been changed to #heading-section-1 (checking on Jekyll 3.7.3 right now).

As a way to figure this out on your own, you can inspect the element and see the id being used on the rendered page.

like image 26
spygi Avatar answered Sep 27 '22 19:09

spygi