21 12 / 2011

Markdown + Urls with Parentheses

Yet another completely random topic… I ran across this when trying to link to a resource on Microsoft’s MSDN site from a Markdown document. The link for the page is:

http://msdn.microsoft.com/en-us/library/dd633694(v=exchg.80).aspx

which as you can see, readily confuses Tumblr as well, which uses Markdown during editing and converts it automatically to the broken HTML seen above. The syntax for defining a link in Markdown looks like this:

[some link](http://some-url.com)

which would then render the link like so: some link

Since the url portion of the link is delimited by ( and ), adding parentheses into the url string confuses the Markdown parser (and different Markdown parsers may actually parse it differently).

The solution is simple, though maybe not obvious — you have to HTML-encode the parentheses when using them in a Markdown link. The url-encoded value for ( is %28 and ) is %29. So our fixed link now looks like this:

[MSDN page](http://msdn.microsoft.com/en-us/library/dd633694%28v=exchg.80%29.aspx)

which now renders and functions as expected: MSDN page

(By the way, who even uses stupid urls with parentheses in them? Microsoft, once again, making the web just a little bit harder to work with. Thanks!)

Tags:

Permalink 21 notes