views:

273

answers:

2

Is the problem me, or Stack Overflow?

If I post a comment or question with this named link, some text, and then an inline link the preview will show correctly but the actual result is strange. All of the text from the start of the first link up to and including the text of the second link is linked to the first destination.

For example:

[strfriend](http://strfriend.com/) is *your* friend:

<http://strfriend.com/vis?re=%28Zip%3A%5cs%2a%5cd%5cd%5cd%5cd%5cd%29%5cs%2a%28State%3A%5cs%2a%5cw%5cw%29&gt;

Results in:

strfriend is your friend:

http://strfriend.com/vis?re=%28Zip%3A%5cs%2a%5cd%5cd%5cd%5cd%5cd%29%5cs%2a%28State%3A%5cs%2a%5cw%5cw%29

Notice how the entire first line is linked, and how the second link actually points to the destination of the first.

Related:

http://stackoverflow.com/questions/217533/links-to-urls-containing-parentheses

+3  A: 

Updated in light of comment:

[strfriend][1] is *your* friend

  [1]: http://strfriend.com/

Results in:

strfriend is your friend

James Burgess
I want the word `strfriend ` to be a link and not the rest of the sentence. I could user the reference-style links, but shouldn't the code I posted be valid syntax? The preview pane even gets it right!
Steve Losh
Updated in light of your comment... The syntax you have above isn't valid Markdown, at least not on here on SO.
James Burgess
MarkDown is just ambiguous this way because valid links could actually contain parentheses. Your solution is good.
Konrad Rudolph
@James It's not valid Markdown? That format for links is shown as an example right on the edit page in the "Formatting Help" box...
Steve Losh
+1  A: 

Escape the parens. Parens are pretty toxic in URLs.

http://www.codinghorror.com/blog/archives/001181.html

It's even worse: those strfriend URLs in the form of

http://strfriend.com/vis?re=(Zip%3A\s*\d\d\d\d\d)\s*(State%3A\s*\w\w)

...are really painful. You'll have to encode almost everything in it. See my edit. Works now, but not worth it IMO.

str friend? more like str ENEMY.

Jeff Atwood
That does work, thanks. It still seems odd that it would render correctly in the preview but not in the final version. Well, maybe not odd if they use different Markdown rendering engines.
Steve Losh
Parentheses in URLs might be toxic, but they're also perfectly valid, and thus the syntax ought to work.
Rob
A URL this crazy should be tinyurl'ed IMO
Jeff Atwood