forked from farneman/javascript-linkify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ba-linkify.min.js
22 lines (22 loc) · 3.92 KB
/
ba-linkify.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
* JavaScript Linkify - v0.4 - 11/16/2012
* https://github.com/farneman/javascript-linkify
*
* Forked from work by Michael Mahemoff & Eli Ellis:
* https://github.com/mahemoff/javascript-linkify
* https://github.com/eliellis/javascript-linkify
*
* Based on the original work by "Cowboy" Ben Alman:
* http://benalman.com/projects/javascript-linkify/
*
* Copyright (c) 2009 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* Some regexps adapted from http://userscripts.org/scripts/review/7122
*/
(function(){var l;HOST_OR_IP="(?:(?:(?:[^\\s!@#$%^&*()_=+[\\]{}\\\\|;:'\",.<>/?]+)\\.)+(?:ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|asia|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|post|pr|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xn--0zwm56d|xn--11b5bs3a9aj6g|xn--3e0b707e|xn--45brj9c|xn--80akhbyknj4f|xn--80ao21a|xn--90a3ac|xn--9t4b11yi5a|xn--clchc0ea0b2g2a9gcd|xn--deba0ad|xn--fiqs8s|xn--fiqz9s|xn--fpcrj9c3d|xn--fzc2c9e2c|xn--g6w251d|xn--gecrj9c|xn--h2brj9c|xn--hgbk6aj7f53bba|xn--hlcj6aya9esc7a|xn--j6w193g|xn--jxalpdlp|xn--kgbechtv|xn--kprw13d|xn--kpry57d|xn--lgbbat1ad8j|xn--mgb9awbf|xn--mgbaam7a8h|xn--mgbayh7gpa|xn--mgbbh1a71e|xn--mgbc0a9azcg|xn--mgberp4a5d4ar|xn--mgbx4cd0ab|xn--o3cw4h|xn--ogbpf8fl|xn--p1ai|xn--pgbs0dh|xn--s9brj9c|xn--wgbh1c|xn--wgbl6a|xn--xkc2al3hye2a|xn--xkc2dl3a5ee0h|xn--yfro4i67o|xn--ygbi2ammx|xn--zckzah|xxx|ye|yt|za|zm|zw)|(?:(?:[0-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}(?:[0-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5]))";
PATH="(?:[;/][^#?<>\\s]*)?";QUERY_FRAG="(?:\\?[^#<>\\s]*)?(?:#[^<>\\s]*)?";URI1="\\b[a-z\\d.-]+://[^<>\\s]+";URI2="\\b"+HOST_OR_IP+PATH+QUERY_FRAG+"(?!\\w)";MAILTO="mailto:";EMAIL="(?:"+MAILTO+")?[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@"+HOST_OR_IP+QUERY_FRAG+"(?!\\w)";URI_RE_LIST=[URI1,URI2,EMAIL];SCHEME_RE=/^[a-z\d.-]+:\/\//i;quotes={"'":"`",">":"<",")":"(","]":"[","}":"{","\u00bb":"\u00ab","\u203a":"\u2039"};default_options={callback:function(d,c,a){if(c){var c='<a href="'+
encodeURI(c)+'" title="'+encodeURI(c)+'"',b,a=a?a.attribs:"",e=" ";for(b in a)e+=b+'="'+a[b]+'" ';b=e.replace(/ $/,"");d=c+b+">"+d+"</a>"}return d},punct_regexp:/(?:[!?.,:;'"]|(?:&|&)(?:lt|gt|quot|apos|raquo|laquo|rsaquo|lsaquo);)$/,twitter:!1,attribs:{}};l=function(d,c){c=c||{};c.twitter&&URI_RE_LIST.push("@[a-zA-Z0-9_]+");URI_RE=RegExp("(?:"+URI_RE_LIST.join("|")+")","ig");var a,b,e="",h=[],j,f,k,i,g;for(a in default_options)void 0===c[a]&&(c[a]=default_options[a]);for(;a=URI_RE.exec(d);)if(a=
a[0],f=URI_RE.lastIndex,k=f-a.length,!/[\/:]/.test(d.charAt(k-1))){do{b=a;g=a.substr(-1);if(i=quotes[g])if(i=a.match(RegExp("\\"+i+"(?!$)","g")),g=a.match(RegExp("\\"+g,"g")),(i?i.length:0)<(g?g.length:0))a=a.substr(0,a.length-1),f--;c.punct_regexp&&(a=a.replace(c.punct_regexp,function(a){f-=a.length;return""}))}while(a.length&&a!==b);b=a;c.twitter&&0==b.indexOf("@")?b="http://twitter.com/"+b.substr(1):SCHEME_RE.test(b)||(b=(-1!==b.indexOf("@")?!b.indexOf(MAILTO)?"":MAILTO:!b.indexOf("irc.")?"irc://":
!b.indexOf("ftp.")?"ftp://":"http://")+b);j!=k&&(h.push([d.slice(j,k),null]),j=f);h.push([a,b])}d&&h.push([d.substr(j),null]);for(a=0;a<h.length;a++)e+=c.callback.apply(null,h[a].concat(c));return e||d};"undefined"==typeof window?module.exports=l:window.linkify=l})();