5

I was modifying an answer to make the links clickable. One of the links would have been:

Raw:

* http://en.wikipedia.org/wiki/Knuth–Morris–Pratt_algorithm

But (at least in the edit preview for the answer, and here on MSO) the URL highlighting (recognition) stops after 'Knuth'. There were analogous problems with the other URL, for the Boyer-Moore string searching algorithm.

I worked around it with:

and could have used:

Raw:

* [Knuth-Morris-Pratt algorithm](http://en.wikipedia.org/wiki/Knuth–Morris–Pratt_algorithm)

* [http://en.wikipedia.org/wiki/Knuth–Morris–Pratt_algorithm](http://en.wikipedia.org/wiki/Knuth–Morris–Pratt_algorithm)

but should I have needed to do either of those? Isn't a dash an OK part of a URL?

7
  • 3
    Dash (-) are correct in URLs but en dash () or em dash () should be encoded to %E2%80%93 and %E2%80%94 respectively. It seems Wikipedia uses an en dash in the title there.
    – Tunaki
    Jul 3, 2016 at 23:04
  • @Tunaki: Ah! That's interesting. I hadn't noticed the orthography until you mentioned it. Thank you! That explains the problem. If you submit it as an answer, I'll accept it. Jul 3, 2016 at 23:07
  • Wikipedia actually uses dashes in its canonical URL, but manages to convert n-dashes to dashes (or Firefox does that for me — I haven't proven which). Jul 3, 2016 at 23:14
  • Test en.wikipedia.org/wiki/Knuth–Morris–Pratt_algorithm Test. Hmm doesn't this say it should work in comments? There might be more to the story here...
    – Tunaki
    Jul 3, 2016 at 23:23
  • @Tunaki: I'm not sure what your comment shows. That link doesn't work for the reason you stated in your first comment. The last 4 links (two formatted, two raw) in the question contain en-dashes but the clickable versions lead to the right page on Wikipedia for me — and the URL in the address bar on the Wikipedia page contains regular dashes, not en-dashes. So, something is fixing the URL so I see the right page. That's useful, but unexpected. Jul 3, 2016 at 23:28
  • @JonathanLeffler it might be due to 2 AM here, but I can see en-dashes in the wikipedia URL after following your first formatted link. The first paragraph of the article does contain hyphens instead (which is wrong), but both the title and the URL of the article contain en-dashes. Which is not surprising since your formatted link explicitly links to the URL with en-dashes. Compare the auto-redirecting version with hyphens in the URL, that should note the redirect under the title. So did I misunderstand something?:) Jul 4, 2016 at 0:16
  • 1
    @AndrasDeak: Hmmm...I think it's safe to say it is confusing (or I'm confused). Now I'm trying again, it seems that Wikipedia does generate URLs containing en-dashes with URL-encoding when I copy from the address bar (https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm). I typed a URL with regular dashes and it was transformed to the version with en-dashes. So, it probably is Wikipedia doing the transform — it is self-coherent. The issue remains 'en-dashes are not allowed in URLs unless URL-encoded'. And what you get when you use copy'n'paste isn't 100% obvious. Jul 4, 2016 at 0:35

1 Answer 1

7

Dash (-) are valid in URLs but:

  • en dash () should be encoded to %E2%80%93.
  • em dash () should be encoded to %E2%80%94.

It seems Wikipedia uses an en dash in the title, so this breaks the automatic link. So this works

https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm

Raw

https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm

As a side-note, at least with Firefox 47.0.1 (latest as of this date), copy-pasting the URL of the Wikipedia page correctly URL-encodes it. It also seems that Wikipedia redirects automatically to the page using en dashes when using simple dashes, probably to avoid this bit of ugliness of URL encoding en dashes.

That said, the Markdown parser could understand that by itself and create correct links for your first example. This post on MSE seems to say it should work in comments (but it doesn't appear to be the case?) and that this feature could be expanded to posts also.

2
  • It didn't work in that comment because you didn't do it correctly. You cannot just place a link, you have to explicitly define it as a link using the [title](link) syntax. This does work.
    – animuson StaffMod
    Jul 4, 2016 at 3:56
  • @animuson I believe this was clear to them from the start, see the second "work-around" by Jonathan in the question: there the solution is the full link syntax, with the link containing proper en-dashes. Jul 4, 2016 at 8:34

You must log in to answer this question.

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