Skip to content
Browse files

optimized the matching `RegExp`s to use fewer capturing parenthesis +…

… moved the plugins into a subfolder
  • Loading branch information...
1 parent 223e873 commit df7b6ffb9576577f0893aaf1ebf095fd6a77ae07 @maranomynet committed Nov 10, 2010
View
2 1.0/jquery.linkify-1.0-test.html
@@ -16,7 +16,7 @@
<!-- links to scripts to test -->
<script src="../../jquery/1.4/jquery-1.4.js"></script>
<script src="jquery.linkify-1.0.js"></script>
- <script src="jquery.linkify-1.0-twitter.js"></script>
+ <script src="plugins/jquery.linkify-1.0-twitter.js"></script>
<script>
/* ==================================================================
View
2 1.0/jquery.linkify-1.0-twitter-min.js
@@ -1,2 +0,0 @@
-// Twitter plugin for jQuery.fn.linkify() 1.0 - MIT/GPL Licensed
-jQuery.extend(jQuery.fn.linkify.plugins,{twitterUser:{re:/(^|["'(]|&lt;|\s)@([a-z0-9_-]+)(([:?]|\.+)?(\s|$)|&gt;|[)"',])/i,tmpl:'$1<a href="http://www.twitter.com/$2">@$2</a>$3'},twitterHashtag:{re:/(^|["'(]|&lt;|\s)(#.+?)(([:?]|\.+)?(\s|$)|&gt;|[)"',])/i,tmpl:function(d,b,a,c){return b+'<a href="http://www.twitter.com/search?q='+encodeURIComponent(a)+'">'+a+'</a>'+c}}});
View
8 1.0/jquery.linkify-1.0.js
@@ -69,12 +69,12 @@
(function($){
- var noProtocolUrl = /(^|["'(]|&lt;|\s)(www\..+?\..+?)(([:?]|\.+)?(\s|$)|&gt;|[)"',])/g,
- httpOrMailtoUrl = /(^|["'(]|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(([:?]|\.+)?(\s|$)|&gt;|[)"',])/g,
+ var noProtocolUrl = /(?:^|["'(]|&lt;|\s)(www\..+?\..+?)(?:(?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/g,
+ httpOrMailtoUrl = /(?:^|["'(]|&lt;|\s)((?:(?:https?|ftp):\/\/|mailto:).+?)(?:(?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/g,
linkifier = function ( html ) {
return html
- .replace( noProtocolUrl, '$1<a href="<``>://$2">$2</a>$3' ) // NOTE: we escape `"http` as `"<``>` to make sure `httpOrMailtoUrl` below doesn't find it as a false-positive
- .replace( httpOrMailtoUrl, '$1<a href="$2">$2</a>$5' )
+ .replace( noProtocolUrl, '<a href="<``>://$1">$1</a>' ) // NOTE: we escape `"http` as `"<``>` to make sure `httpOrMailtoUrl` below doesn't find it as a false-positive
+ .replace( httpOrMailtoUrl, '<a href="$1">$1</a>' )
.replace( /"<``>/g, '"http' ); // reinsert `"http`
},
View
2 1.0/plugins/jquery.linkify-1.0-twitter-min.js
@@ -0,0 +1,2 @@
+// Twitter plugin for jQuery.fn.linkify() 1.0 - MIT/GPL Licensed
+jQuery.extend(jQuery.fn.linkify.plugins,{twitterUser:{re:/(?:^|["'(]|&lt;|\s)@([a-z0-9_-]+)(?:(?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/i,tmpl:'<a href="http://www.twitter.com/$1">@$1</a>'},twitterHashtag:{re:/(?:^|["'(]|&lt;|\s)(#.+?)(?:(?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/i,tmpl:function(b,a){return'<a href="http://www.twitter.com/search?q='+encodeURIComponent(a)+'">'+a+'</a>'}}});
View
12 1.0/jquery.linkify-1.0-twitter.js → 1.0/plugins/jquery.linkify-1.0-twitter.js
@@ -4,7 +4,7 @@
Version 1.0
- Copyright (c) 2009
+ Copyright (c) 2010
Már Örlygsson (http://mar.anomy.net/) &
Hugsmiðjan ehf. (http://www.hugsmidjan.is)
@@ -14,13 +14,13 @@
*/
jQuery.extend(jQuery.fn.linkify.plugins, {
twitterUser: {
- re: /(^|["'(]|&lt;|\s)@([a-z0-9_-]+)(([:?]|\.+)?(\s|$)|&gt;|[)"',])/i,
- tmpl: '$1<a href="http://www.twitter.com/$2">@$2</a>$3'
+ re: /(?:^|["'(]|&lt;|\s)@([a-z0-9_-]+)(?:(?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/i,
+ tmpl: '<a href="http://www.twitter.com/$1">@$1</a>'
},
twitterHashtag: {
- re: /(^|["'(]|&lt;|\s)(#.+?)(([:?]|\.+)?(\s|$)|&gt;|[)"',])/i,
- tmpl: function (match, before, hashTag, after) {
- return before+'<a href="http://www.twitter.com/search?q='+ encodeURIComponent(hashTag) +'">'+hashTag+'</a>'+after;
+ re: /(?:^|["'(]|&lt;|\s)(#.+?)(?:(?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/i,
+ tmpl: function (match, hashTag) {
+ return '<a href="http://www.twitter.com/search?q='+ encodeURIComponent(hashTag) +'">'+hashTag+'</a>';
}
}
});

0 comments on commit df7b6ff

Please sign in to comment.
Something went wrong with that request. Please try again.