[kramdown-users] url-encoding feature suggestion

Matt Neuburg matt at tidbits.com
Sat Dec 17 12:25:50 EST 2011


On Dec 17, 2011, at 12:33 AM, Thomas Leitner wrote:

> On 2011-08-18 07:52 -0700 Matt Neuburg wrote:
>> Wouldn't it be cool if kramdown would do URL-encoding? For example,
>> suppose I put this (the URL being copied out of my browser - I hope
>> this comes through the email):
>> 
>>  [A town in Slovakia](http://en.wikipedia.org/wiki/Košice)
>> 
>> The result is:
>> 
>>  <a href="http://en.wikipedia.org/wiki/Košice">A town in Slovakia</a>
>> 
>> But it should be URL-encoded:
>> 
>>  <a href="http://en.wikipedia.org/wiki/Kos%CC%8Cice">A town in
>> Slovakia</a>
>> 
>> I can fix this in my own post-processing in RubyFrontier, of course,
>> but I suggest that having kramdown perform the URL-encoding itself
>> would be a cool feature. m.
> 
> 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

m.


--
matt neuburg, phd = matt at tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
Programming iOS 4! http://www.apeth.net/matt/default.html#iosbook
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com




More information about the kramdown-users mailing list