Well, it looks like this forum is doing this correctly. Any ruby-forum.com dev's out there that can explain how they are both escaping HTML and calling auto linking URLs?
I had the same problem. Here is a simplified version that worked for me:
def auto_link_urls (text) url_regex = / ([a-zA-Z][0-9a-zA-Z+\-\.]*:\/\/|www\.) [0-9a-zA-Z;\/?:@&=+$\.\-_!~*'()%]+ (\#[0-9a-zA-Z;\/?:@&=+$\.\-_!~*'()%]+)? /x
text.gsub(url_regex) do |link| link = 'http://' + link if $1 == 'www.' link_text = block_given? ? yield(link) : link '<a href="' + link + '">' + link_text + '</a>' end end
It doesn't detect already linked URLs (I didn't need it) but it allows a wider range of URLs (ftp://…, for example) and works with HTMLized URLs (...?foo=1&bar=2...) and some other special case original version doesn't seem to detect (Example Domain).