markdown link to header

HyperlinkGitlabMarkdown

Hyperlink Problem Overview


I'm using GitLab to write a read.me file.

I tried to create a link to a header. According to the wiki an id should be automatically created:

see here

I created a header using:

### 1. This is my Header

and tried to create a link to it:

[link](#1--this-is-my-header)

but it is not working. What am I doing wrong?

Hyperlink Solutions


Solution 1 - Hyperlink

In the Documentation you link to we learn that...

> The IDs are generated from the content of the header according to the > following rules: > > 1. All text is converted to lowercase. > 2. All non-word text (e.g., punctuation, HTML) is removed. > 3. All spaces are converted to hyphens. > 4. Two or more hyphens in a row are converted to one. > 5. If a header with the same ID has already been generated, a unique incrementing number is appended, starting at 1.

Note rule 4: "Two or more hyphens in a row are converted to one." However, the example you tried has two hyphens in a row (after the 1). Remove one of them and you should have it.

[link](#1-this-is-my-header)

From time to time I have encountered a unique header which is converted into an ID in some non-obvious way. A quick way to work out the ID is to use your browser's view source and/or inspect tools to view the HTML source code. For example, you might find the following HTML for your example:

<h3 id="1-this-is-my-header">1. This is my Header</h3>

Then just use the contents of the id attribute with a hash to link to that header: #1-this-is-my-header.

Solution 2 - Hyperlink

Markdown IDs are generated using some rules i've been able to google: (text to lowercase, non-word punctuation removed, spaces converted to hyphens, two or more hyphens in a row converted to one, naming collisions have incremented number appended, ...)

I found an easy way to figure out what the anchor link should be. Use your browser's HTML inspector to inspect the header you want to link to. The header tag's ID should be what you use. So for example my heading looks like this in the HTML inspector:

<h2 id="markdown-header-changing-plsql-parameters-and-shared-developers-lifecycle">
  Changing PL/SQL parameters and shared developer's lifecycle
</h2>

And I can link to it in markup like so:

[See instructions below](#markdown-header-changing-plsql-parameters-and-shared-developers-lifecycle)

And now "See instructions below" is linked to my header anchor.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser7431005View Question on Stackoverflow
Solution 1 - HyperlinkWaylanView Answer on Stackoverflow
Solution 2 - HyperlinkRick TilleyView Answer on Stackoverflow