[kramdown-users] url-encoding feature suggestion

Thomas Leitner t_leitner at gmx.at
Sun Dec 18 03:09:51 EST 2011

On 2011-12-17 09:25 -0800 Matt Neuburg wrote:
> On Dec 17, 2011, at 12:33 AM, Thomas Leitner wrote:
> > I have looked a bit around and it seems that no other markup
> > processor does this. The problem is: How to detect an already
> > correctly encoded URL? This is not possible, I think, and therefore
> > kramdown has to assume that the URLs are already nicely encoded.
> require 'URI'
> def encode_if_not_encoded(s)
>   s2 = URI.decode(s)
>   (s == s2) ? URI.encode(s) : s
> end
> s = 'http://en.wikipedia.org/wiki/Košice'
> s = encode_if_not_encoded(s)
> p s
> s = encode_if_not_encoded(s)
> p s

Okay, but what about URLs that look like they are correctly encoded
but are not? For example, the URL `http://example.com/hallo/%2520`. If
we state that kramdown automatically encodes URLs, this URL would be
left as is using your `encode_if_not_encoded` method. But what if this
URL is *not* already encoded and should be encoded to

I have to admit that this is a rather pathological case but

Another reason for leaving it as it is: Now you can just copy and paste
a kramdown document into a mail or anywhere else and the links will
*just work*. If we would allow invalid URLs in a kramdown document,
this would not be the case anymore. For example, your link above
doesn't work in my mail client.

Best regards,

More information about the kramdown-users mailing list