How do I prevent auto-generated links in the GitHub wiki?
Asked Answered
S

7

106

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?

Steelworker answered 7/9, 2014 at 0:28 Comment(2)
Put the URL into a code environment (i.e., in the middle of backticks)Paleolith
VSCode 1.63 (Nov. 2021, 7 years later) should not generate links for URL without http(s)://. See my edited answer below.Harned
H
119

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

Harned answered 7/9, 2014 at 6:55 Comment(10)
Not ideal, but this is the only workable solution I've come across so far. Thanks.Steelworker
Using the punctuation char &#46; was also mentioned at the bottom of the same GistSquashy
No need for a long tag name https<k>://exa</k>mple.com/ will do it @Squashy : That no longer works, not even https&#58;//example&#46;com/ ...Groundnut
For emails you can use foo<span>@</span>example.comPectoral
@Pectoral Thank you for this neat trick. I have included your comment in the answer for more visibility.Harned
A shorter (and imo cleaner) way is just to add a self-closing <span/>, at a location that breaks the url detectability, eg. right before the com. Example: www.foobar.<span/>comTrishatriskelion
@Trishatriskelion Interresting option, thank you. I have included your comment in the answer for more visibility.Harned
@Harned 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 <span/> right before the first dot.Trishatriskelion
@Harned Also, I realized that it is better to use an empty <area> tag (or one mentioned here) than a <span/> 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)Trishatriskelion
@Trishatriskelion THank you for your tests and your edit: very much appreciated.Harned
C
44

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
Conaway answered 22/7, 2019 at 19:38 Comment(3)
This is the best solution. Works for filenames as well as URLs. Also works in VSCode. But doesn't seem to work in SO comments. example&#46;com example.comKhan
Unless someone broke VS Code in 2020, this doesn't work in VS Code any longer.Chatav
Works in Discourse, too.Trost
E
17

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

Eggert answered 19/2, 2020 at 18:15 Comment(3)
I like this as it does not hamper the readability of raw filesKentonkentucky
Quick note the HTML is &#8203;Quass
Worked like a charm for disabling automatic JIRA ticket recognition for dummy ticket #s! Thank you!Conciliatory
K
16

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

http\://www.foobar.com
Kiser answered 22/6, 2019 at 6:31 Comment(1)
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.Multicellular
P
8

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

Penney answered 25/10, 2020 at 18:52 Comment(2)
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/GitSweetening
For emails you can just place a backslash before the @. ie. test\@gmail.comElijah
N
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

Nauplius answered 23/8, 2021 at 17:54 Comment(0)
C
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.

Cass answered 4/5, 2021 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.