What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 128 Stack Exchange communities.

How do I add a link to a URL containing parentheses () (or "round brackets" by heathens)?

For example:

http://msdn.microsoft.com/en-us/library/aa752574(VS.85).aspx

The parentheses around "VS.85" causes it to look like this:

Markdown:

[IHtmlDocument2 reference](http://msdn.microsoft.com/en-us/library/aa752574(VS.85).aspx)

Output renders as

IHtmlDocument2 reference

share|improve this question

migrated from stackoverflow.com Aug 10 '09 at 18:13

This question came from our site for professional and enthusiast programmers.

1  
Can I further note that the preview is not consistent with the result at times. I detailed this in my "duplicate" meta.stackexchange.com/questions/18323 –  dlamblin Aug 28 '09 at 17:35
4  
The team eventually decided that this was a bug, and has fixed it. –  Pops Jan 20 '11 at 15:36
    
It is poor form to have parentheses in a URL, many RegExes will presume text with either parenthesis is not a URL. –  Cayetano Gonçalves May 21 '11 at 18:48
1  
@RVWard - Can you provide any real world examples? RFC3986 states parenthesis are valid in general URI's and RFC1738 explicitly indicates parenthesis are valid in URL's. And the link above is from Microsoft.com so I'm very doubtful that Microsoft would publish MSDN documentation links with invalid/unescaped URL's (regardless of what some might say about M$ & standards compliance ;) I'm not sure what standard you're using to classify it as "poor form." –  Marcus Pope Jan 10 '12 at 2:05
    
@PopularDemand Too bad there isn't a status-completed here. –  Asad Feb 16 '13 at 7:10

4 Answers 4

There are many ways to format urls in Markdown. Parentheses work better with some methods than others.

1. Bare             - http://example.com/test(1).html
2. Bare, encoded    - http://example.com/test%281%29.html
3. Delimited        - <http://example.com/test(1).html>
4. Hyperlink        - with <a href="http://example.com/test(1).html">parens</a>
5. Markdown Link #1 - with [parens][1]
6. Markdown Link #1 - with [parens at end][2]
7. Markdown Link #2 - with [parens](http://example.com/test(1).html)
8. Markdown Link #2 - with [parens at end](http://example.com/test(1))  

  [1]: http://example.com/test(1).html
  [2]: http://example.com/test_(test)
  1. Bare - http://example.com/test(1).html
  2. Bare, encoded - http://example.com/test%281%29.html
  3. Delimited - http://example.com/test(1).html
  4. Hyperlink - with parens
  5. Markdown Link #1 - with parens
  6. Markdown Link #1 - with parens at end
  7. Markdown Link #2 - with parens
  8. Markdown Link #2 - with parens at end

Note also that parenthetical sections in msdn links are optional, so:

http://msdn.microsoft.com/en-us/library/5471dc8s(VS.80).aspx

could be linked to, instead, as:

http://msdn.microsoft.com/en-us/library/5471dc8s.aspx

See also The Problem With URLs for Jeff's blog post about coming up with a solution for Stack Overflow.

Other issues with URLs

Sometimes URLs can fail to link correctly because they contain disallowed characters. In these cases encode the characters using the % notation. Previously characters such as () [] ' and * were not allowed but the server-side Markdown renderer has been modified to accept them now. Currently the only (known) characters that aren't accepted are ones with accents, graves, diaeresis etc. For example: é or ö, although if it's a wikipedia link you can just use the unadorned character. (A suggestion to have these characters supported has been made on uservoice.)

share|improve this answer
    
TIL parenthetical sections in MSDN links are optional. Mind = blown. –  Mathias Bynens Dec 11 '11 at 6:59
2  
Of course, the parentheticals are needed if you want to link to a page about an earlier release... –  SamB Jan 31 '12 at 7:04
    
Would approach #4 be the preferred way to do this in comments? It doesn't seem to work for me. Here's <a href="hadoop.apache.org/docs/r2.3.0/api/org/apache/hadoop/mapreduce/…, org.apache.hadoop.fs.Path...)">an example</a>. –  Nick Chammas Jun 4 at 15:01
    
@NickChammas when you're commenting, click the help link to the right of the text box, that will show how to do links in comments. –  Sam Hasler Jun 4 at 15:05
    
@Sam - It's not clear from the help how to link to a URL with parentheses in a comment. Approaches 4, 7, and 8 above look like what I want (in-line linking of text to URL with parentheses), but none of them appear to work in comments. –  Nick Chammas Jun 4 at 15:14
    
OK let me try again with this link: http://hadoop.apache.org/docs/r2.3.0/api/org/apache/hadoop/mapreduce/lib/input/‌​FileInputFormat.html#setInputPaths(org.apache.hadoop.mapreduce.Job, org.apache.hadoop.fs.Path...) OK... [here we go!](hadoop.apache.org/docs/r2.3.0/api/org/apache/hadoop/mapreduce/…, org.apache.hadoop.fs.Path...)) –  Nick Chammas Jun 4 at 15:24
1  
@NickChammas There's a "space" character in that URL. You need to encode it as "%20" thus: an example –  Sam Hasler Jun 4 at 15:26
    
Ahhhhhh, OK! Thank you for helping me track that down. –  Nick Chammas Jun 4 at 15:28

Use the <a> notation instead of the [ ] notation.

e.g. <a href="http://msdn.microsoft.com/en-us/library/aa752574(VS.85).aspx">IHtmlDocument2 reference</a>

share|improve this answer

You can do it like this:

link to [IHtmlDocument2 reference][1]

   [1]: http://msdn.microsoft.com/en-us/library/aa752574(VS.85).aspx

For what it's worth, () are parentheses. Braces are {}.

share|improve this answer
    
As long as we're discussing semantics, I've also heard parentheses called "round braces", which I think is a kind-of neat and more generic/accurate term for them. –  Kyle Falconer Jun 4 at 14:28

FYI, if you're trying to do this in Octopress or Jeckyll, you'll see that some of these methods don't work.

You can use the delimiters inside the parens like this:

[My Link](<http://example.com/test(1)>)

Which looks like this:

My Link

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .