# 防止超链接

**URL:** https://meta.discourse.org/t/prevent-hyperlink/44482
**Category:** Support
**Created:** [2016年五月19日 07:49 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482 "2016-05-19T07:49:11Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![precessor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/precessor/32/120664_2.png) [@precessor](https://meta.discourse.org/u/precessor)
#### Post date: [2016年五月19日 07:49 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/1 "2016-05-19T07:49:11Z")

</div>

How can I prevent a [www.example.com](http://www.example.com) URL from becoming a hyperlink, without (ab)using another formatting feature such as inline code formatting?

I notice I can quote: “[www.example.com](http://www.example.com)”, but I’d like to avoid that. Is it possible to somehow escape the auto-link change as I create/edit a post?

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [2016年五月19日 07:52 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/2 "2016-05-19T07:52:06Z")

</div>

Backslashes?  
`www\.example\.com`  
www.example.com

---

<div class="post-metadata">

### Author: ![burke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/burke/32/4211_2.png) [@burke](https://meta.discourse.org/u/burke)
#### Post date: [2018年一月7日 02:11 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/3 "2018-01-07T02:11:15Z")

</div>

> [@Mittineague](#):
>
> Backslashes?  
> `www\.example\.com`  
> [www.example.com](http://www.example.com)

I noticed this solution does not work any longer. It was the first thing I tried before googling and finding this post. I’ll keep looking for a solution. Surprisingly, even `www&#46;example&#46;com` is converted into a hyperlink if on the same line as a regular link.

Looks like I’ll be using `www<span>.</span>example<span>.</span>com`  
www.example.com

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018年一月7日 02:27 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/4 "2018-01-07T02:27:42Z")

</div>

Why in the world would you do any of that when you can simply use a proper code span with the ` key?

`www.example.com`

See [Markdown Reference](http://commonmark.org/help)

---

<div class="post-metadata">

### Author: ![notriddle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/notriddle/32/133055_2.png) [@notriddle](https://meta.discourse.org/u/notriddle)
#### Post date: [2018年一月7日 02:28 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/5 "2018-01-07T02:28:03Z")

</div>

Because it’s not code?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018年一月7日 02:28 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/6 "2018-01-07T02:28:56Z")

</div>

Preformatted text has other meanings. I reject the premise in the first post, it reads like “how can I avoid hitting myself if I really like hitting myself?”

---

<div class="post-metadata">

### Author: ![burke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/burke/32/4211_2.png) [@burke](https://meta.discourse.org/u/burke)
#### Post date: [2018年一月7日 19:47 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/7 "2018-01-07T19:47:33Z")

</div>

I just want to be able to type out a domain name as text (without formatting/styling) and have enough OCD not only go to length of using `<span>.</span>`, but also to spend time finding out why `\.` doesn’t work as expected and post about it.

Fortunately, not everyone is cursed with my level of OCD. 😉

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018年一月7日 21:34 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/8 "2018-01-07T21:34:02Z")

</div>

Zero width Unicode spacers would also work but anyone who copies and pastes that URL is in for a surprise.. and not the good kind! Dunno if @sam has any other ideas but the request is really odd.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2018年一月7日 22:44 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/9 "2018-01-07T22:44:38Z")

</div>

Yeah bypassing linkify is not easy:

[https://github.com/markdown-it/markdown-it/blob/master/lib/rules\_core/linkify.js](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.js)

and

[https://github.com/markdown-it/linkify-it](https://github.com/markdown-it/linkify-it)

We had a similar request with complaints about m.sc being autolinked.

I do wonder if we should side with @Vitaly here and disable linkify fuzzy out of the box. Cause [https://cnn.com](https://cnn.com) will continue to work even if linkify fuzzy is disabled. So all you do is lose out on `www.cnn.com`

I think we should probably amend the test here to have a simpler bypass for fuzzy, just not sure what it would be

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [2018年一月8日 16:12 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/10 "2018-01-08T16:12:57Z")

</div>

Well, using ` does turn the text into a `<code></code>` section instead of `<pre></pre>` which is preformatted text.

@notriddle Technically speaking there is a difference, but there really is no reason why `<code></code>` can’t be acceptable – URL’s are a form of “code” afterall.

---

<div class="post-metadata">

### Author: ![burke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/burke/32/4211_2.png) [@burke](https://meta.discourse.org/u/burke)
#### Post date: [2018年一月18日 17:01 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/11 "2018-01-18T17:01:53Z")

</div>

> [@schungx](#):
>
> @notriddle Technically speaking there is a difference, but there really is no reason why \<code\>\</code\> can’t be acceptable – URL’s are a form of “code” afterall.

Well said. The few cases where it has come up for me are when I’m trying to point someone to one url instead of another – i.e., when I’m trying to de-emphasize a URL. For example:

> **A:** Just use [smile.amazon.com](http://smile.amazon.com) instead of amazon.com and select OpenMRS, Inc. as your charity.

> **B:** Just use [smile.amazon.com](http://smile.amazon.com) instead of `amazon.com` and select OpenMRS, Inc. as your charity.

`B` is certainly a reasonable workaround; personally I prefer `A`. But, this is such an embarrassingly small issue, I can’t justify anyone (including myself) spending time on it. I’ve got `amazon<span>.</span>com` as a workaround for the 1-2 times I’ll ever need this again, so I’m happy… clearly afflicted with too much focus on meaningless details… but happy.

The awesome folks working on Discourse have more important things to do. I recommend focusing on other ways to continue making Discourse the most awesome forum software in the world and let this thread fade away. I’m sure I’ll re-discover this thread in a few years when this comes up again, so won’t need to post about it ever again. 🤓

(and I promise to not suggest a Discourse GSoC project to add support for www\.example\.com)

---

<div class="post-metadata">

### Author: ![surety](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/surety/32/156849_2.png) [@surety](https://meta.discourse.org/u/surety)
#### Post date: [2019年十月9日 01:40 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/12 "2019-10-09T01:40:11Z")

</div>

我们论坛的主要目的是讨论一家名为 [Alarm.com](http://Alarm.com) 的公司，因此用户发帖时几乎每两个主题中就会有一个提到 [Alarm.com](http://Alarm.com)。这导致我们不可避免地会大量意外链接到 [Alarm.com](http://Alarm.com)。

我曾尝试完全禁用自动链接功能，但这引发了更大的问题：用户无法在单独一行输入 URL 来生成预览卡片（onebox）。

我们非常希望能有一种方法，可以仅禁用模糊匹配链接，同时保留完整 URL 的自动链接功能。请问这是否可行？

---

<div class="post-metadata">

### Author: ![surety](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/surety/32/156849_2.png) [@surety](https://meta.discourse.org/u/surety)
#### Post date: [2019年十月11日 01:22 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/13 "2019-10-11T01:22:10Z")

</div>

跟进一下……看起来，正如 Sam 建议的那样，如果你将 `vendor/assets/javascripts/markdown-it.js` 中的 `defaultOptions` 里的 `fuzzyLink` 设置为 `false`，就能解决我的问题。但这样做会带来一个大麻烦，因为我们不想每次更新时都手动重新应用这个修改。

后来我偶然发现了一个更简单的解决方案。`markdown linkify tlds` 设置是一个顶级域名列表，模糊链接会假定这些顶级域名为 URL。如果你移除列表中的所有顶级域名，只添加一个实际上永远不会出现在帖子中的假顶级域名，就可以有效地禁用 `fuzzyLink`。列表中至少需要一个顶级域名，否则任何以 `.` 结尾的内容都会被当作链接处理。

因此，无需修改代码，我们可以通过从该设置中移除真实的顶级域名并添加一个假的顶级域名来禁用 `fuzzyLink`。

---

<div class="post-metadata">

### Author: ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://meta.discourse.org/u/EricGT)
#### Post date: [2020年七月5日 12:39 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/14 "2020-07-05T12:39:08Z")

</div>

另一种抑制 [自动链接单词](https://meta.discourse.org/t/linkify-words-in-post/82193) 的变通方法。

在文本中间添加 `<span></span>`。

* * *

详情

我们的网站在“自动链接单词”组件主题中添加了 `SWI-Prolog`。

为了防止 `SWI-Prolog` 被转换为链接（例如 [SWI-Prolog](https://www.swi-prolog.org/)），同时也避免显示为代码段（例如 `SWI-Prolog`），可以在文本中间插入 `<span></span>`，例如 `SWI<span></span>-Prolog`。这样，“自动链接单词”功能将无法识别该文本。由于 `<span></span>` 渲染后在浏览器中不可见，因此该方法在特定场景下（如 SWI-Prolog）能够按预期生效。

---

<div class="post-metadata">

### Author: ![dfabulich](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dfabulich/32/108716_2.png) [@dfabulich](https://meta.discourse.org/u/dfabulich)
#### Post date: [2021年九月23日 02:19 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/15 "2021-09-23T02:19:07Z")

</div>

您可以使用 `<span></span>` 将链接化的域名包裹起来，而不是将其插入到中间。这在讨论公司名称或其他名称中包含点号的大小写专有名词时非常有用，例如 `<span>itch.io</span>`。

例如，如果您在 Markdown 编辑器中直接输入 `itch.io`，它会被自动链接化：[itch.io](http://itch.io)

但您也可以输入 `<span>itch.io</span>`，这样它就不会被链接化：itch.io

您不必在链接中间插入 `<span></span>`，例如 `itch<span></span>.io`，但这样做也有效：itch.io

（如果 @precessor 或版主能将“✅ 解决方案”的标记改为这个答案，而不是当前选中的解决方案，那就太好了；旧的解决方案在 2016 年有效，但现在已不再适用。）

---

<div class="post-metadata">

### Author: ![mr\_scary](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mr_scary/32/134418_2.png) [@mr\_scary](https://meta.discourse.org/u/mr_scary)
#### Post date: [2022年三月4日 15:49 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/16 "2022-03-04T15:49:31Z")

</div>

> [@dfabulich](#):
>
> 您不必在链接中间插入 `<span></span>`，例如 `itch<span></span>.io`

这只是我今天起作用的唯一方法。

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [2022年三月4日 19:04 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/17 "2022-03-04T19:04:48Z")

</div>

Itch`.`io

```plaintext

Itch`.`io

```

预格式化工具栏上有，而且用起来更快 😉

---

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [2022年三月4日 21:53 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/18 "2022-03-04T21:53:20Z")

</div>

但那会改变格式，所以你为什么要选择一个不改变格式的选项呢？

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [2022年三月4日 22:36 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/19 "2022-03-04T22:36:57Z")

</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年六月8日 12:36 UTC](https://meta.discourse.org/t/prevent-hyperlink/44482/20 "2024-06-08T12:36:47Z")

</div>

此主题已在 2942 天后自动关闭。不再允许回复。
