site/js/Autolinker.min.js

26 lines
45 KiB
JavaScript
Raw Permalink Normal View History

/*!
* Autolinker.js
* 3.14.2
*
* Copyright(c) 2020 Gregory Jacobs <greg@greg-jacobs.com>
* MIT License
*
* https://github.com/gregjacobs/Autolinker.js
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Autolinker=t()}(this,function(){"use strict";function s(e,t){if(Array.prototype.indexOf)return e.indexOf(t);for(var u=0,r=e.length;u<r;u++)if(e[u]===t)return u;return-1}function t(e,t){for(var u=e.length-1;0<=u;u--)!0===t(e[u])&&e.splice(u,1)}function z(e){throw new Error("Unhandled case for value: '"+e+"'")}var u=(e.prototype.setTagName=function(e){return this.tagName=e,this},e.prototype.getTagName=function(){return this.tagName||""},e.prototype.setAttr=function(e,t){return this.getAttrs()[e]=t,this},e.prototype.getAttr=function(e){return this.getAttrs()[e]},e.prototype.setAttrs=function(e){return Object.assign(this.getAttrs(),e),this},e.prototype.getAttrs=function(){return this.attrs||(this.attrs={})},e.prototype.setClass=function(e){return this.setAttr("class",e)},e.prototype.addClass=function(e){for(var t,u=this.getClass(),r=this.whitespaceRegex,n=u?u.split(r):[],a=e.split(r);t=a.shift();)-1===s(n,t)&&n.push(t);return this.getAttrs().class=n.join(" "),this},e.prototype.removeClass=function(e){for(var t,u=this.getClass(),r=this.whitespaceRegex,n=u?u.split(r):[],a=e.split(r);n.length&&(t=a.shift());){var i=s(n,t);-1!==i&&n.splice(i,1)}return this.getAttrs().class=n.join(" "),this},e.prototype.getClass=function(){return this.getAttrs().class||""},e.prototype.hasClass=function(e){return-1!==(" "+this.getClass()+" ").indexOf(" "+e+" ")},e.prototype.setInnerHTML=function(e){return this.innerHTML=e,this},e.prototype.setInnerHtml=function(e){return this.setInnerHTML(e)},e.prototype.getInnerHTML=function(){return this.innerHTML||""},e.prototype.getInnerHtml=function(){return this.getInnerHTML()},e.prototype.toAnchorString=function(){var e=this.getTagName(),t=this.buildAttrsStr();return["<",e,t=t?" "+t:"",">",this.getInnerHtml(),"</",e,">"].join("")},e.prototype.buildAttrsStr=function(){if(!this.attrs)return"";var e=this.getAttrs(),t=[];for(var u in e)e.hasOwnProperty(u)&&t.push(u+'="'+e[u]+'"');return t.join(" ")},e);function e(e){void 0===e&&(e={}),this.tagName="",this.attrs={},this.innerHTML="",this.whitespaceRegex=/\s+/,this.tagName=e.tagName||"",this.attrs=e.attrs||{},this.innerHTML=e.innerHtml||e.innerHTML||""}function c(e,t,i){function u(e){var t="";return e.scheme&&e.host&&(t+=e.scheme+"://"),e.host&&(t+=e.host),e.path&&(t+="/"+e.path),e.query&&(t+="?"+e.query),e.fragment&&(t+="#"+e.fragment),t}function r(e,t){var u=t/2,r=Math.ceil(u),n=-1*Math.floor(u),a="";return n<0&&(a=e.substr(n)),e.substr(0,r)+i+a}var n,a=null==i?(i="&hellip;",n=3,8):(n=i.length,i.length);if(e.length<=t)return e;var s,o,c,h,l=t-n,p=(s={},(c=(o=e).match(/^([a-z]+):\/\//i))&&(s.scheme=c[1],o=o.substr(c[0].length)),(c=o.match(/^(.*?)(?=(\?|#|\/|$))/i))&&(s.host=c[1],o=o.substr(c[0].length)),(c=o.match(/^\/(.*?)(?=(\?|#|$))/i))&&(s.path=c[1],o=o.substr(c[0].length)),(c=o.match(/^\?(.*?)(?=(#|$))/i))&&(s.query=c[1],o=o.substr(c[0].length)),(c=o.match(/^#(.*?)$/i))&&(s.fragment=c[1]),s);if(!p.query||(h=p.query.match(/^(.*?)(?=(\?|\#))(.*?)$/i))&&(p.query=p.query.substr(0,h[1].length),e=u(p)),e.length<=t)return e;if(p.host&&(p.host=p.host.replace(/^www\./,""),e=u(p)),e.length<=t)return e;var g="";if(p.host&&(g+=p.host),g.length>=l)return p.host.length==t?(p.host.substr(0,t-n)+i).substr(0,l+a):r(g,l).substr(0,l+a);var d="";if(p.path&&(d+="/"+p.path),p.query&&(d+="?"+p.query),d){if(l<=(g+d).length)return(g+d).length==t?(g+d).substr(0,t):(g+r(d,l-g.length)).substr(0,l+a);g+=d}if(p.fragment){var f="#"+p.fragment;if(l<=(g+f).length)return(g+f).length==t?(g+f).substr(0,t):(g+r(f,l-g.length)).substr(0,l+a);else g+=f}if(p.scheme&&p.host){var m=p.scheme+"://";if((g+m).length<l)return(m+g).substr(0,t)}if(g.length<=t)return g;var A="";return 0<l&&(A=g.substr(-1*Math.floor(l/2))),(g.substr(0,Math.ceil(l/2))+i+A).substr(0,l+a)}var r=(n.prototype.build=function(e){return new u({tagName:"a",attrs:this.createAttrs(e),innerHtml:this.processAnchorText(e.getAnchorText())})},n.prototype.createAttrs=function(e){var t={href:e.get
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function i(e){this.__jsduckDummyDocProp=null,this.matchedText="",this.offset=0,this.tagBuilder=e.tagBuilder,this.matchedText=e.matchedText,this.offset=e.offset}var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var u in t)t.hasOwnProperty(u)&&(e[u]=t[u])})(e,t)};function h(e,t){function u(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(u.prototype=t.prototype,new u)}var l,R=function(){return(R=Object.assign||function(e){for(var t,u=1,r=arguments.length;u<r;u++)for(var n in t=arguments[u])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)},B=(h(p,l=a),p.prototype.getType=function(){return"email"},p.prototype.getEmail=function(){return this.email},p.prototype.getAnchorHref=function(){return"mailto:"+this.email},p.prototype.getAnchorText=function(){return this.email},p);function p(e){var t=l.call(this,e)||this;return t.email="",t.email=e.email,t}var g,d=(h(f,g=a),f.prototype.getType=function(){return"hashtag"},f.prototype.getServiceName=function(){return this.serviceName},f.prototype.getHashtag=function(){return this.hashtag},f.prototype.getAnchorHref=function(){var e=this.serviceName,t=this.hashtag;switch(e){case"twitter":return"https://twitter.com/hashtag/"+t;case"facebook":return"https://www.facebook.com/hashtag/"+t;case"instagram":return"https://instagram.com/explore/tags/"+t;default:throw new Error("Unknown service name to point hashtag to: "+e)}},f.prototype.getAnchorText=function(){return"#"+this.hashtag},f);function f(e){var t=g.call(this,e)||this;return t.serviceName="",t.hashtag="",t.serviceName=e.serviceName,t.hashtag=e.hashtag,t}var m,A=(h(b,m=a),b.prototype.getType=function(){return"mention"},b.prototype.getMention=function(){return this.mention},b.prototype.getServiceName=function(){return this.serviceName},b.prototype.getAnchorHref=function(){switch(this.serviceName){case"twitter":return"https://twitter.com/"+this.mention;case"instagram":return"https://instagram.com/"+this.mention;case"soundcloud":return"https://soundcloud.com/"+this.mention;default:throw new Error("Unknown service name to point mention to: "+this.serviceName)}},b.prototype.getAnchorText=function(){return"@"+this.mention},b.prototype.getCssClassSuffixes=function(){var e=m.prototype.getCssClassSuffixes.call(this),t=this.getServiceName();return t&&e.push(t),e},b);function b(e){var t=m.call(this,e)||this;return t.serviceName="twitter",t.mention="",t.mention=e.mention,t.serviceName=e.serviceName,t}var x,y=(h(F,x=a),F.prototype.getType=function(){return"phone"},F.prototype.getPhoneNumber=function(){return this.number},F.prototype.getNumber=function(){return this.getPhoneNumber()},F.prototype.getAnchorHref=function(){return"tel:"+(this.plusSign?"+":"")+this.number},F.prototype.getAnchorText=function(){return this.matchedText},F);function F(e){var t=x.call(this,e)||this;return t.number="",t.plusSign=!1,t.number=e.number,t.plusSign=e.plusSign,t}var v,w=(h(C,v=a),C.prototype.getType=function(){return"url"},C.prototype.getUrlMatchType=function(){return this.urlMatchType},C.prototype.getUrl=function(){var e=this.url;return this.protocolRelativeMatch||this.protocolUrlMatch||this.protocolPrepended||(e=this.url="http://"+e,this.protocolPrepended=!0),e},C.prototype.getAnchorHref=function(){return this.getUrl().replace(/&amp;/g,"&")},C.prototype.getAnchorText=function(){var e=this.getMatchedText();return this.protocolRelativeMatch&&(e=this.stripProtocolRelativePrefix(e)),this.stripPrefix.scheme&&(e=this.stripSchemePrefix(e)),this.stripPrefix.www&&(e=this.stripWwwPrefix(e)),this.stripTrailingSlash&&(e=this.removeTrailingSlash(e)),this.decodePercentEncoding&&(e=this.removePercentEncoding(e)),e},C.prototype.stripSchemePrefix=function(e){return e.replace(this.schemePrefixRegex,"")},C.prototype.stripWwwPrefix=function(e){return e.replace(this.wwwPrefixRegex,"$1")},C.prototype.stripProtocolRelativePrefix=function(e){return e.replace(this.protocol
//# sourceMappingURL=Autolinker.min.js.map