The twitter plugin has just been upgraded to (optionally) search for links in the twitter text and activate them as link.

So I thought I'd share the linkify code.

UK EVENTAttend ffconf.org 2024

The conference for people who are passionate about the web. 8 amazing speakers with real human interaction and content you can't just read in a blog post or watch on a tiktok!

String.prototype.linkify = function() {
  return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:% \?\/.=]+[^\.,\)\s*$]/g, function(m) {
    return m.link(m);
  });
};

Short and sweet - will return a string with the URLs as links. Note that if the linkify function encounters a real link, it will break the link - ideally use this code with text you know may contain a plain text link.

For example, assuming status is an element on the page, and twitter.text is our text to search for links within:

status.innerHTML = twitter.text.linkify();

The function has been tested in IE7, Firefox 2, Safari 2 and Opera 9. It has also been tested with domains with ports, paths and query strings.

I could see this being turned in to a bookmarklet to scan the current page to enable links, for instance in a forum where the link has been pasted in and not been converted (though the regex would need a tweak, or something altogether smarter may be required).

Let me know if you have any questions or feedback in case of mistakes.