防止超链接

How can I prevent a 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”, but I’d like to avoid that. Is it possible to somehow escape the auto-link change as I create/edit a post?

Backslashes?
www\.example\.com
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.example.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

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 commonmark.org/help

Because it’s not code?

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?”

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. :wink:

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.

Yeah bypassing linkify is not easy:

https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.js

and

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 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

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.

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 instead of amazon.com and select OpenMRS, Inc. as your charity.

B: Just use 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. :nerd_face:

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

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

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

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

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

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

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

另一种抑制 自动链接单词 的变通方法。

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


详情

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

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

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

例如,如果您在 Markdown 编辑器中直接输入 itch.io,它会被自动链接化:itch.io

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

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

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

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

Itch.io


Itch`.`io

预格式化工具栏上有,而且用起来更快 :wink:

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

因为格式不重要。重要的是你得到什么。这里的目的是防止超链接,而我的解决方案仍然是最简单、最快的 :wink: