# Markdown 链接到锚点不工作吗？

**URL:** https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175
**Category:** Support
**Created:** [2020年五月2日 13:08 UTC](https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175 "2020-05-02T13:08:35Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Paul\_King](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paul_king/32/165426_2.png) [@Paul\_King](https://meta.discourse.org/u/Paul_King)
#### Post date: [2020年五月2日 13:08 UTC](https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/1 "2020-05-02T13:08:35Z")

</div>

你好，我肯定是我哪里做错了，但想不通为什么帖子内部的锚点链接无法正常工作。

例如，在我页面的帖子中 ‘[https://nzarchitecture.net.nz/t/terms-of-service/15076](https://nzarchitecture.net.nz/t/terms-of-service/15076)’  
链接：  
`* [重要条款](https://nzarchitecture.net.nz/t/terms-of-service/15076#heading--important-terms)`

并没有跳转到页面下方的这个标题：  
`## [重要条款](https://nzarchitecture.net.nz/t/terms-of-service/15076#heading--important-terms)`

我漏掉了什么？  
查看标准/原始 Discourse 服务条款页面的 Markdown 作为示例，这_看起来_是正确的语法。

---

<div class="post-metadata">

### Author: ![xrav3nz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xrav3nz/32/76894_2.png) [@xrav3nz](https://meta.discourse.org/u/xrav3nz)
#### Post date: [2020年五月2日 15:02 UTC](https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/2 "2020-05-02T15:02:07Z")

</div>

> [@Paul\_King](#):
>
> 不会跳转到页面下方的这个标题：  
> `## [重要条款](https://nzarchitecture.net.nz/t/terms-of-service/15076#heading--important-terms)`

正如 [Linking to a heading within a post or topic](https://meta.discourse.org/t/deep-linking-to-headings-anchors/47552) 所述，没有标准的 Markdown 方法来创建带有锚点的标题。

恐怕您必须使用 HTML：

```plaintext
<h2 id='heading--important-terms'>重要条款</h2>

```

> **快速演示**
>
> [跳转到演示末尾](#heading--end-of-demo)
> 
> ```plaintext
> [跳转到演示末尾](#heading--end-of-demo)
> 
> ```
> 
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> |  
> v
> 
> ## 演示结束
> 
> ```plaintext
> <h2 id='heading--end-of-demo'>演示结束</h2>
> 
> ```

---

<div class="post-metadata">

### Author: ![Paul\_King](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paul_king/32/165426_2.png) [@Paul\_King](https://meta.discourse.org/u/Paul_King)
#### Post date: [2020年五月2日 15:05 UTC](https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/3 "2020-05-02T15:05:39Z")

</div>

> [@xrav3nz](#):
>
> 正如 [深入链接到标题（锚点）](https://meta.discourse.org/t/deep-linking-to-headings-anchors/47552) 所述，目前没有标准的 Markdown 方式来创建带锚点的标题。
> 
> 恐怕你得使用 HTML：

谢谢 xrax3nz  
我目前确实正在采用这种方法。不过，如果你查看本论坛标准“使用条款”页面中的 Markdown 源码，会发现其语法看起来相当不同。我正试图弄明白其中的原因。

---

<div class="post-metadata">

### Author: ![xrav3nz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xrav3nz/32/76894_2.png) [@xrav3nz](https://meta.discourse.org/u/xrav3nz)
#### Post date: [2020年五月2日 15:11 UTC](https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/4 "2020-05-02T15:11:01Z")

</div>

查看 [Updated Terms of Service Template](https://meta.discourse.org/t/updated-terms-of-service-template/103384) 中提供的未格式化 Markdown，我看不出有任何区别？也许我漏掉了什么？

链接定义如下：

```plaintext
- [重要条款](#heading--important-terms)

```

标题如下：

```plaintext
<h2 id="heading--important-terms"><a href="#heading--important-terms">重要条款</a></h2>

```

---

<div class="post-metadata">

### Author: ![Paul\_King](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paul_king/32/165426_2.png) [@Paul\_King](https://meta.discourse.org/u/Paul_King)
#### Post date: [2020年五月2日 15:15 UTC](https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/5 "2020-05-02T15:15:53Z")

</div>

> [@xrav3nz](#):
>
> 查看 [更新后的服务条款模板](https://meta.discourse.org/t/updated-terms-of-service-template/103384) 中提供的未格式化 Markdown，我看不出有任何区别？也许我漏掉了什么？

嗯，有意思。  
我是通过复制本论坛的服务条款并粘贴到我自己的论坛新帖子中来生成 Markdown 的——这生成了看起来完全不同的语法（长话短说，但基本上是我内置的服务条款不知何故被删除了，而这一切都是为了重建它们）  
也许这就是我的问题，当我尝试在不同站点之间粘贴时，可能会添加了多余的 URL 信息。  
。  
编辑 - 谢谢你的链接 - 那些模板非常有用。可惜没有简单的方法将它们放入原始的内置类别中。

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2024年六月25日 01:20 UTC](https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/6 "2024-06-25T01:20:25Z")

</div>



---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2024年六月25日 08:50 UTC](https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/7 "2024-06-25T08:50:36Z")

</div>

对于 Markdown 版本，您现在可以包含一个标题：

`### 我的标题`

### 我的标题

然后通过单击/长按其旁边的链接来复制它创建的自动锚点链接：

`https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/7#my-heading-1`

[https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/7#my-heading-1](https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/7#my-heading-1)

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2024年六月25日 08:52 UTC](https://meta.discourse.org/t/markdown-links-to-anchors-not-working/150175/8 "2024-06-25T08:52:04Z")

</div>


