(function(n,t){typeof define=="function"&&define.amd?define("urlize",[],t):typeof exports=="object"?module.exports=t():n.urlize=t(n.b)})(this,function(){function s(n,t){return n.substr(0,t.length)==t}function r(n,t){return n.substr(n.length-t.length,t.length)==t}function u(n,t){for(var r=0,i=0;;)if(i=n.indexOf(t,i),i!=-1)r++,i+=t.length;else break;return r}function e(n){var t=n.indexOf(":");return n=n.substring(0,t).toLowerCase()+n.substring(t),n.indexOf("%")==-1||n.match(f)?encodeURI(n):n}function n(n,t){var i=n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;");return t&&!t.django_compatible&&(i=i.replace(/\//g,"&#47;")),i}function k(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function o(n){var t;return t=n.length==2&&typeof n[1]=="object"?n[1]:{nofollow:n[1],autoescape:n[2],trim_url_limit:n[3],target:n[4]},"django_compatible"in t||(t.django_compatible=!0),t}function i(i,f){function yt(n,t){return((f.trim==="http"||f.trim==="www")&&(n=n.replace(/^https?:\/\//i,"")),f.trim==="www"&&(n=n.replace(/^www\./i,"")),t===undefined&&(t=f.trim_url_limit),t&&n.length>t)?n.substr(0,t-3)+"...":n}var nt,tt,bt,st,g,et,ot,ht;f=o(arguments);var lt=!1,pt=f.django_compatible?v:y,at=f.django_compatible?h:c,ct=f.django_compatible?l:a,wt=new RegExp("^www\\.|^(?!http)\\w[^@]+\\.("+(f.top_level_domains||w).join("|")+")$","i"),ut=t(i,pt);for(nt=0;nt<ut.length;nt++)if(tt=ut[nt],bt=undefined,tt.indexOf(".")!=-1||tt.indexOf("@")!=-1||tt.indexOf(":")!=-1){var ft="",d=tt,it="";for(g=0;g<at.length;g++)st=at[g],r(d,st)&&(d=d.substr(0,d.length-st.length),it=st+it);for(g=0;g<ct.length;g++)et=ct[g][0],ot=ct[g][1],s(d,et)&&(d=d.substr(et.length),ft=ft+et),r(d,ot)&&u(d,ot)==u(d,et)+1&&(d=d.substr(0,d.length-ot.length),it=ot+it);var rt=undefined,vt=f.nofollow?' rel="nofollow"':"",kt=f.target?' target="'+f.target+'"':"";d.match(p)?rt=e(d):d.match(wt)?rt=e("http://"+d):d.indexOf(":")==-1&&d.match(b)&&(rt="mailto:"+d,vt="");rt?(ht=yt(d),f.autoescape&&(ft=n(ft,f),it=n(it,f),rt=k(rt),ht=n(ht,f)),d='<a href="'+rt+'"'+vt+kt+">"+ht+"<\/a>",ut[nt]=ft+d+it):lt||f.autoescape&&(ut[nt]=n(tt,f))}else lt||f.autoescape&&(ut[nt]=n(tt,f));return ut.join("")}var t,f;t=t||function(n){var i=String.prototype.split,t=/()??/.exec("")[1]===n;return function(r,u,f){if(Object.prototype.toString.call(u)!=="[object RegExp]")return i.call(r,u,f);var o=[],c=(u.ignoreCase?"i":"")+(u.multiline?"m":"")+(u.extended?"x":"")+(u.sticky?"y":""),s=0,u=new RegExp(u.source,c+"g"),l,e,h,a;for(r+="",t||(l=new RegExp("^"+u.source+"$(?!\\s)",c)),f=f===n?-1>>>0:f>>>0;e=u.exec(r);){if(h=e.index+e[0].length,h>s&&(o.push(r.slice(s,e.index)),!t&&e.length>1&&e[0].replace(l,function(){for(var t=1;t<arguments.length-2;t++)arguments[t]===n&&(e[t]=n)}),e.length>1&&e.index<r.length&&Array.prototype.push.apply(o,e.slice(1)),a=e[0].length,s=h,o.length>=f))break;u.lastIndex===e.index&&u.lastIndex++}return s===r.length?(a||!u.test(""))&&o.push(""):o.push(r.slice(s)),o.length>f?o.slice(0,f):o}}();f=/%(?![0-9A-Fa-f]{2})/;var h=[".",",",":",";"],c=[".",",",":",";",".)"],l=[["(",")"],["<",">"],["&lt;","&gt;"]],a=[["(",")"],["<",">"],["&lt;","&gt;"],["“","”"],["‘","’"]],v=/(\s+)/,y=/([\s<>"]+)/,p=/^https?:\/\/\w/i,w=["com","edu","gov","int","mil","net","org"],b=/^\S+@\S+\.\S+$/;return i.test={},i.test.split=t,i.test.convert_arguments=o,i})