标记链接到页眉

我正在使用 GitLab 编写一个 read.me 文件。

我尝试创建一个头部的链接。根据 wiki,应该自动创建一个 id:

看这里

我创建了一个标题,使用:

### 1. This is my Header

并试图创建一个链接:

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

但是没有用。 我做错了什么?

80001 次浏览

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.

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.

There is a simpler way than the inspector, at least in GitLab-flavored mardown : hover over the header and a "chain" icon appears : right-click on it and copy the link.

header with clickable chain