~adeodato/ blog/ entries/ 2008/ 02/ 02/ Markdown links with newlines in the anchor text

Markdown links with newlines in the anchor text

Links in Markdown can be done in a couple ways. First, similarly to HTML links, where you place the link next to the anchor text, like this:

  I am a [Debian](http://www.debian.org) Developer.

Or, if you feel this clutters your paragraphs too much, you can choose an alternate syntax, which I prefer (particulary handy for very long links):

  I am a [Debian][] Developer. Bla bla bla...

    [debian]: http://www.debian.org

There is however a gotcha with this alternate syntax, namely, anchor text with spaces in them. This works fine:

  I study Computer Science in [this University][].

    [this University]: http://www.ua.es

But this does not:

  Some years ago, I started studying Computer Science in [this
  University][]. Bla bla bla...

    [this University]: http://www.ua.es

This actually happens quite a lot when formatting the paragraphs in the editor, which made this otherwise-pleasant syntax almost a no-go for me.

(Well, to be honest you could use it like this, but still:

  Some years ago, I started studying Computer Science in [this
  University][uni]. Bla bla bla...

    [uni]: http://www.ua.es

)


There is a beta version of Markdown in experimental that almost fixes the problem. This version introduces a new but similar syntax for links: you can omit the second pair of empty brackets. And when using that newer syntax, there is code in the program to change newlines into a space when looking for the link definition. It is not applied to the code path of the old syntax, though, which is a pity.

This is all explained in bug #459885, with a patch as well (that applies both to 1.0.1 and 1.0.2). You can find packages with that patch applied here.