views:

108

answers:

2

Is there a Javascript library that exposes a function to automatically turn URLs and email addresses into clickable links? Basically I'm looking for something that duplicates the Rails helper auto_link().

+5  A: 

Autolink may be what you're looking for.

Jonathan Sampson
A: 

EDIT: My bad, I totally misread/misunderstood the question. Left original answer for informative purposes.

Not off the top of my head. However it doesn't sound too hard to write one yourself:

function UrlToLink(url) {
    // 1. check if url IS a url or email using a regex
    // 2. if it isnt return null/false
    // 3. create a DOM `<a></a>` element and populate the href attribute with url (mailto:url if email) and the inner text
    // 4. return element
}

Usage:

document.appendChild(UrlToLink("http://a.url.com/"));

Finding regex's to match url's and email addresses isnt very hard ex: url, email

Darko Z