96

On a GitHub wiki page, if I type:

www.foobar.com

GitHub automatically assumes this is a URL and makes the text a hyperlink to http://www.foobar.com. However, sometimes I do not want a hyperlink to be created. Is there a way to stop this behavior? Perhaps some sort of markdown?

SamB
  • 9,039
  • 5
  • 49
  • 56
david
  • 1,814
  • 1
  • 16
  • 19
  • Put the URL into a code environment (i.e., in the middle of backticks) – MrTux Sep 07 '14 at 00:47
  • VSCode 1.63 (Nov. 2021, 7 years later) should *not* generate links for URL *without* `http(s)://`. See my [edited answer below](https://stackoverflow.com/a/25707855/6309). – VonC Nov 22 '21 at 14:16

7 Answers7

106

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 3
    Not ideal, but this is the only workable solution I've come across so far. Thanks. – david Sep 07 '14 at 21:59
  • 21
    Using the punctuation char `.` was also mentioned at the bottom of the same Gist – kitsu.eb Sep 21 '17 at 16:07
  • 1
    No need for a long tag name `https://example.com/` will do it @kitsu.eb : That no longer works, not even `https://example.com/` ... – davidkonrad Mar 27 '19 at 12:44
  • For emails you can use `foo@example.com` – geekley Oct 10 '20 at 21:19
  • @geekley Thank you for this neat trick. I have included your comment in the answer for more visibility. – VonC Oct 10 '20 at 21:29
  • A shorter (and imo cleaner) way is just to add a self-closing ``, at a location that breaks the url detectability, eg. right before the `com`. Example: `www.foobar.com` – Venryx Apr 13 '21 at 03:23
  • 1
    @Venryx Interresting option, thank you. I have included your comment in the answer for more visibility. – VonC Apr 13 '21 at 06:15
  • @VonC Apologies. While my version above worked in the vscode Markdown preview window, it did not work (as written) on Github; well actually, it works on Github, but not for url-like strings that starts with "www". So instead, if the string starts with "www", you have to put the `` right before the first dot. – Venryx Apr 13 '21 at 11:09
  • 2
    @VonC Also, I realized that it is better to use an empty `` tag (or [one mentioned here](https://stackoverflow.com/a/7854998/2441655)) than a `` tag, for two reasons: 1) It's one character shorter. 2) It's more spec-compliant. (doing a "self-closing" span tag is technically not correct HTML, so will cause container/nesting issues on some sites) I will add the change to your answer if you don't mind. (if I did it wrong, feel free to revise) – Venryx Apr 13 '21 at 11:17
  • @Venryx THank you for your tests and your edit: very much appreciated. – VonC Apr 13 '21 at 12:03
41

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
Justin Slone
  • 451
  • 4
  • 5
15

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

KyleMit
  • 30,350
  • 66
  • 462
  • 664
13

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

http\://www.foobar.com
SamB
  • 9,039
  • 5
  • 49
  • 56
  • 3
    Many auto-links are applied after the content is rendered. In my experience, `\:` or any other escaping will leave the `:` unaffected, but the link will still be applied to the URl-looking string. – cautionbug Dec 11 '19 at 16:17
7

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

vstelmakh
  • 742
  • 1
  • 11
  • 19
  • This method worked for me, editing in VS and viewing in TFS/Git. Escaping was ok when viewing in VS Code, but not in TFS/Git – ThatITBloke Oct 12 '21 at 17:04
3

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
TonyG
  • 1,432
  • 12
  • 31
2

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.

HughZhang
  • 21
  • 1