如何防止 GitHub wiki 中的自动生成链接?

在 GitHub 的 wiki 页面上,如果我输入:

www.foobar.com

GitHub 自动假定这是一个 URL,并将文本作为到 http://www.foobar.com的超链接。但是,有时我不希望创建超链接。有办法阻止这种行为吗?也许是某种折扣?

46686 次浏览

Update Nov. 2021, VSCode 1.63:

This issue should be allievated with issue 136198 "markdown preview wrongly creates links "

While "markdown.preview.linkify": false will disable linkify features entirely, setting md.linkify.fuzzyLink to false will disable it only for links without http(s) header.
Which, I think, is a better alternative, and it's already supported by markdown-it.


Original answer (2014): This isn't limited to wiki page, and is part of the GFM (GitHub Flavored Markdown) url autolinking feature.

Putting them in `` can work but display the url as a code: foo http://example.com bar.

foo `http://example.com` bar

Another trick (mentioned in this gist) is

ht<span>tp://</span>example.com

That will display http://example.com as regular text.

In your case (without the http://)

w<span>ww.</span>foobar.com

That would also display www.foobar.com as regular text.

geekley adds in the comments:

For emails, you can use foo<span>@</span>example.com


Venryx suggests in the comments a shorter/cleaner solution:

Just add one of the void element tags (I prefer <area>), at a location that breaks the URL detectability, eg. right before the first dot.

Example: www<area>.foobar.com

You can also just apply a backslash escape to the colon (or any of the other punctuation, apparently), like this:

http\://www.foobar.com

Also, if you are having a issue with something other than a URL auto-linking I found escaping the . works as well.

Example:

foobar.web -> foobar&#46;web

You can use a zero-width space to prevent most auto-linkers from interpreting characters as a URL

Here's an example with a zero width space inserted between https and :

https​://example.com/

To insert one, you can copy from the url above or this page

See also this thread on twitter

Note: This can make it potentially very confusing for anyone trying to copy and paste the link manually into a URL, because it won't resolve, and it'll be unclear why. This works best for joke URLs that you don't ever actually want to be traversed like www.great-answer-on-stack-overflow-kyle.com

Would suggest to use zero-width no-break space.
In HTML could be used as Unicode char reference: &#xfeff; or &#65279;

Benefits are:

  • prevents autolinks (obviously)
  • invisible
  • no unexpected line breaks
  • readable in source

Examples

For urls insert between http and :
https​&#65279;://example.com/ → https​://example.com/

For emails insert after @:
user@&#65279;example.com → user@example.com

in my case,
i used
# some&#46;thing
in title , then i get a title without link outside.

some.thing

and use
[some.thing](#something)
as link.
"#something" is come from the link previewed in web.

I suggest this is just a more complete and currently correct answer.

It was brought up that VSCode behaves differently from Github. It seems Github auto-URL handling acts on the "www." prefix (perhaps other triggers), while VSCode auto-converts any period/fullstop-delimited text that ends with a suffix that is a IANA registered country-code TLD. VSCode does not auto-complete any text that begins with "www." like Github does. Compare the three images below and note the placement of tags and how each environment renders the text.

Note that the only mechanism that suppresses all auto-URL rendering is (the most ugly) to put a tag before every period. It probably doesn't matter what the tag is. 'span' may do in all cases. I use 'nowiki' because it's consistent here and in MediaWiki and perhaps others.

Knowing the rules, however, it appears "the answer" to suppressing auto-URL rendering is dependent on the text.

  • If it starts with "www.", go with the ugly solution. See the last two lines of the Github render and note that the tag just before the last period will suppress rendering only for the last part of the text.
  • But if the text does not begin with "www.", a single tag before the final period is all that is required for both VSC and GH.
  • Both environments are subject to rules that evaluate the text. At some point, either or both may auto-convert .gov, .net, other common TLDs, and eventually any valid ggTLD like .online, .xyz, or .aaa. To future-proof your text, consider using the ugly approach for all text like this, where the text isn't code that will be rendered with backticks.
  • The actual tag seems unimportant, whether <nowiki/>, <span/>, or <k>. Personally I recommend nowiki because it's already a recognized tag for exactly this purpose.
  • About &# HTML encoding, I tried the recommendations here and the text was not processed. I did not include examples here, but feel free to substitute any in-text tag with character encoding to see how it works for you.

VSCode editor:
raw VSCode markdown

VSCode preview:
same code rendered in VSCode markdown preview

Github Readme.md:
same code pushed to repo and rendered by Github