matthewford (owner)

Revisions

  • 9ff8fe matthew... Mon May 18 04:57:03 -0700 2009
gist: 113431 Download_button fork
public
Public Clone URL: git://gist.github.com/113431.git
Embed All Files: show embed
twitter linkify #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function linkify(s) {
       var entities = {
           '"' : '"',
           '&' : '&',
           '<' : '&lt;',
           '>' : '&gt;'
       };
       
       return s.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(m) {
           return m.link(m);
       }).replace(/(^|[^\w])(@[\d\w\-]+)/g, function(d, m1, m2) {
           return m1 + '@<a href="http://twitter.com/' + m2.substr(1) + '">' + m2.substr(1) + '</a>';
       }).replace(/"&<>/, function (m) {
           return entities[m];
       });
   };