61

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
  • 8,218
  • 5
  • 44
  • 52
david
  • 1,386
  • 1
  • 12
  • 18

6 Answers6

69

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

Venryx
  • 8,962
  • 7
  • 50
  • 61
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • 1
    Not ideal, but this is the only workable solution I've come across so far. Thanks. – david Sep 07 '14 at 21:59
  • 14
    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
  • @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
27

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
  • 311
  • 3
  • 5
8

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
  • 8,218
  • 5
  • 44
  • 52
  • 2
    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
8

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

KyleMit
  • 45,382
  • 53
  • 367
  • 544
1

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
  • 622
  • 1
  • 7
  • 15
0

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.