Reputation: 89313
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().
Upvotes: 1
Views: 646
Reputation: 38880
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
Upvotes: 0