1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216 |
- var tmp = {};
- (function (global, factory) {
- global.Autolinker = factory();
- }(tmp, function () { 'use strict';
-
- function defaults(dest, src) {
- for (var prop in src) {
- if (src.hasOwnProperty(prop) && dest[prop] === undefined) {
- dest[prop] = src[prop];
- }
- }
- return dest;
- }
-
- function ellipsis(str, truncateLen, ellipsisChars) {
- var ellipsisLength;
- if (str.length > truncateLen) {
- if (ellipsisChars == null) {
- ellipsisChars = '…';
- ellipsisLength = 3;
- }
- else {
- ellipsisLength = ellipsisChars.length;
- }
- str = str.substring(0, truncateLen - ellipsisLength) + ellipsisChars;
- }
- return str;
- }
-
- function indexOf(arr, element) {
- if (Array.prototype.indexOf) {
- return arr.indexOf(element);
- }
- else {
- for (var i = 0, len = arr.length; i < len; i++) {
- if (arr[i] === element)
- return i;
- }
- return -1;
- }
- }
-
- function remove(arr, fn) {
- for (var i = arr.length - 1; i >= 0; i--) {
- if (fn(arr[i]) === true) {
- arr.splice(i, 1);
- }
- }
- }
-
- function splitAndCapture(str, splitRegex) {
- if (!splitRegex.global)
- throw new Error("`splitRegex` must have the 'g' flag set");
- var result = [], lastIdx = 0, match;
- while (match = splitRegex.exec(str)) {
- result.push(str.substring(lastIdx, match.index));
- result.push(match[0]);
- lastIdx = match.index + match[0].length;
- }
- result.push(str.substring(lastIdx));
- return result;
- }
-
- function throwUnhandledCaseError(theValue) {
- throw new Error("Unhandled case for value: '" + theValue + "'");
- }
-
- var HtmlTag = (function () {
-
- function HtmlTag(cfg) {
- if (cfg === void 0) { cfg = {}; }
-
- this.tagName = '';
-
- this.attrs = {};
-
- this.innerHTML = '';
-
- this.whitespaceRegex = /\s+/;
- this.tagName = cfg.tagName || '';
- this.attrs = cfg.attrs || {};
- this.innerHTML = cfg.innerHtml || cfg.innerHTML || '';
- }
-
- HtmlTag.prototype.setTagName = function (tagName) {
- this.tagName = tagName;
- return this;
- };
-
- HtmlTag.prototype.getTagName = function () {
- return this.tagName || '';
- };
-
- HtmlTag.prototype.setAttr = function (attrName, attrValue) {
- var tagAttrs = this.getAttrs();
- tagAttrs[attrName] = attrValue;
- return this;
- };
-
- HtmlTag.prototype.getAttr = function (attrName) {
- return this.getAttrs()[attrName];
- };
-
- HtmlTag.prototype.setAttrs = function (attrs) {
- Object.assign(this.getAttrs(), attrs);
- return this;
- };
-
- HtmlTag.prototype.getAttrs = function () {
- return this.attrs || (this.attrs = {});
- };
-
- HtmlTag.prototype.setClass = function (cssClass) {
- return this.setAttr('class', cssClass);
- };
-
- HtmlTag.prototype.addClass = function (cssClass) {
- var classAttr = this.getClass(), whitespaceRegex = this.whitespaceRegex, classes = (!classAttr) ? [] : classAttr.split(whitespaceRegex), newClasses = cssClass.split(whitespaceRegex), newClass;
- while (newClass = newClasses.shift()) {
- if (indexOf(classes, newClass) === -1) {
- classes.push(newClass);
- }
- }
- this.getAttrs()['class'] = classes.join(" ");
- return this;
- };
-
- HtmlTag.prototype.removeClass = function (cssClass) {
- var classAttr = this.getClass(), whitespaceRegex = this.whitespaceRegex, classes = (!classAttr) ? [] : classAttr.split(whitespaceRegex), removeClasses = cssClass.split(whitespaceRegex), removeClass;
- while (classes.length && (removeClass = removeClasses.shift())) {
- var idx = indexOf(classes, removeClass);
- if (idx !== -1) {
- classes.splice(idx, 1);
- }
- }
- this.getAttrs()['class'] = classes.join(" ");
- return this;
- };
-
- HtmlTag.prototype.getClass = function () {
- return this.getAttrs()['class'] || "";
- };
-
- HtmlTag.prototype.hasClass = function (cssClass) {
- return (' ' + this.getClass() + ' ').indexOf(' ' + cssClass + ' ') !== -1;
- };
-
- HtmlTag.prototype.setInnerHTML = function (html) {
- this.innerHTML = html;
- return this;
- };
-
- HtmlTag.prototype.setInnerHtml = function (html) {
- return this.setInnerHTML(html);
- };
-
- HtmlTag.prototype.getInnerHTML = function () {
- return this.innerHTML || "";
- };
-
- HtmlTag.prototype.getInnerHtml = function () {
- return this.getInnerHTML();
- };
-
- HtmlTag.prototype.toAnchorString = function () {
- var tagName = this.getTagName(), attrsStr = this.buildAttrsStr();
- attrsStr = (attrsStr) ? ' ' + attrsStr : '';
- return ['<', tagName, attrsStr, '>', this.getInnerHtml(), '</', tagName, '>'].join("");
- };
-
- HtmlTag.prototype.buildAttrsStr = function () {
- if (!this.attrs)
- return "";
- var attrs = this.getAttrs(), attrsArr = [];
- for (var prop in attrs) {
- if (attrs.hasOwnProperty(prop)) {
- attrsArr.push(prop + '="' + attrs[prop] + '"');
- }
- }
- return attrsArr.join(" ");
- };
- return HtmlTag;
- }());
-
- function truncateSmart(url, truncateLen, ellipsisChars) {
- var ellipsisLengthBeforeParsing;
- var ellipsisLength;
- if (ellipsisChars == null) {
- ellipsisChars = '…';
- ellipsisLength = 3;
- ellipsisLengthBeforeParsing = 8;
- }
- else {
- ellipsisLength = ellipsisChars.length;
- ellipsisLengthBeforeParsing = ellipsisChars.length;
- }
- var parse_url = function (url) {
- var urlObj = {};
- var urlSub = url;
- var match = urlSub.match(/^([a-z]+):\/\//i);
- if (match) {
- urlObj.scheme = match[1];
- urlSub = urlSub.substr(match[0].length);
- }
- match = urlSub.match(/^(.*?)(?=(\?|#|\/|$))/i);
- if (match) {
- urlObj.host = match[1];
- urlSub = urlSub.substr(match[0].length);
- }
- match = urlSub.match(/^\/(.*?)(?=(\?|#|$))/i);
- if (match) {
- urlObj.path = match[1];
- urlSub = urlSub.substr(match[0].length);
- }
- match = urlSub.match(/^\?(.*?)(?=(#|$))/i);
- if (match) {
- urlObj.query = match[1];
- urlSub = urlSub.substr(match[0].length);
- }
- match = urlSub.match(/^#(.*?)$/i);
- if (match) {
- urlObj.fragment = match[1];
-
- }
- return urlObj;
- };
- var buildUrl = function (urlObj) {
- var url = "";
- if (urlObj.scheme && urlObj.host) {
- url += urlObj.scheme + "://";
- }
- if (urlObj.host) {
- url += urlObj.host;
- }
- if (urlObj.path) {
- url += "/" + urlObj.path;
- }
- if (urlObj.query) {
- url += "?" + urlObj.query;
- }
- if (urlObj.fragment) {
- url += "#" + urlObj.fragment;
- }
- return url;
- };
- var buildSegment = function (segment, remainingAvailableLength) {
- var remainingAvailableLengthHalf = remainingAvailableLength / 2, startOffset = Math.ceil(remainingAvailableLengthHalf), endOffset = (-1) * Math.floor(remainingAvailableLengthHalf), end = "";
- if (endOffset < 0) {
- end = segment.substr(endOffset);
- }
- return segment.substr(0, startOffset) + ellipsisChars + end;
- };
- if (url.length <= truncateLen) {
- return url;
- }
- var availableLength = truncateLen - ellipsisLength;
- var urlObj = parse_url(url);
-
- if (urlObj.query) {
- var matchQuery = urlObj.query.match(/^(.*?)(?=(\?|\#))(.*?)$/i);
- if (matchQuery) {
-
- urlObj.query = urlObj.query.substr(0, matchQuery[1].length);
- url = buildUrl(urlObj);
- }
- }
- if (url.length <= truncateLen) {
- return url;
- }
- if (urlObj.host) {
- urlObj.host = urlObj.host.replace(/^www\./, "");
- url = buildUrl(urlObj);
- }
- if (url.length <= truncateLen) {
- return url;
- }
-
- var str = "";
- if (urlObj.host) {
- str += urlObj.host;
- }
- if (str.length >= availableLength) {
- if (urlObj.host.length == truncateLen) {
- return (urlObj.host.substr(0, (truncateLen - ellipsisLength)) + ellipsisChars).substr(0, availableLength + ellipsisLengthBeforeParsing);
- }
- return buildSegment(str, availableLength).substr(0, availableLength + ellipsisLengthBeforeParsing);
- }
- var pathAndQuery = "";
- if (urlObj.path) {
- pathAndQuery += "/" + urlObj.path;
- }
- if (urlObj.query) {
- pathAndQuery += "?" + urlObj.query;
- }
- if (pathAndQuery) {
- if ((str + pathAndQuery).length >= availableLength) {
- if ((str + pathAndQuery).length == truncateLen) {
- return (str + pathAndQuery).substr(0, truncateLen);
- }
- var remainingAvailableLength = availableLength - str.length;
- return (str + buildSegment(pathAndQuery, remainingAvailableLength)).substr(0, availableLength + ellipsisLengthBeforeParsing);
- }
- else {
- str += pathAndQuery;
- }
- }
- if (urlObj.fragment) {
- var fragment = "#" + urlObj.fragment;
- if ((str + fragment).length >= availableLength) {
- if ((str + fragment).length == truncateLen) {
- return (str + fragment).substr(0, truncateLen);
- }
- var remainingAvailableLength2 = availableLength - str.length;
- return (str + buildSegment(fragment, remainingAvailableLength2)).substr(0, availableLength + ellipsisLengthBeforeParsing);
- }
- else {
- str += fragment;
- }
- }
- if (urlObj.scheme && urlObj.host) {
- var scheme = urlObj.scheme + "://";
- if ((str + scheme).length < availableLength) {
- return (scheme + str).substr(0, truncateLen);
- }
- }
- if (str.length <= truncateLen) {
- return str;
- }
- var end = "";
- if (availableLength > 0) {
- end = str.substr((-1) * Math.floor(availableLength / 2));
- }
- return (str.substr(0, Math.ceil(availableLength / 2)) + ellipsisChars + end).substr(0, availableLength + ellipsisLengthBeforeParsing);
- }
-
- function truncateMiddle(url, truncateLen, ellipsisChars) {
- if (url.length <= truncateLen) {
- return url;
- }
- var ellipsisLengthBeforeParsing;
- var ellipsisLength;
- if (ellipsisChars == null) {
- ellipsisChars = '…';
- ellipsisLengthBeforeParsing = 8;
- ellipsisLength = 3;
- }
- else {
- ellipsisLengthBeforeParsing = ellipsisChars.length;
- ellipsisLength = ellipsisChars.length;
- }
- var availableLength = truncateLen - ellipsisLength;
- var end = "";
- if (availableLength > 0) {
- end = url.substr((-1) * Math.floor(availableLength / 2));
- }
- return (url.substr(0, Math.ceil(availableLength / 2)) + ellipsisChars + end).substr(0, availableLength + ellipsisLengthBeforeParsing);
- }
-
- function truncateEnd(anchorText, truncateLen, ellipsisChars) {
- return ellipsis(anchorText, truncateLen, ellipsisChars);
- }
-
- var AnchorTagBuilder = (function () {
-
- function AnchorTagBuilder(cfg) {
- if (cfg === void 0) { cfg = {}; }
-
- this.newWindow = false;
-
- this.truncate = {};
-
- this.className = '';
- this.newWindow = cfg.newWindow || false;
- this.truncate = cfg.truncate || {};
- this.className = cfg.className || '';
- }
-
- AnchorTagBuilder.prototype.build = function (match) {
- return new HtmlTag({
- tagName: 'a',
- attrs: this.createAttrs(match),
- innerHtml: this.processAnchorText(match.getAnchorText())
- });
- };
-
- AnchorTagBuilder.prototype.createAttrs = function (match) {
- var attrs = {
- 'href': match.getAnchorHref()
- };
- var cssClass = this.createCssClass(match);
- if (cssClass) {
- attrs['class'] = cssClass;
- }
- if (this.newWindow) {
- attrs['target'] = "_blank";
- attrs['rel'] = "noopener noreferrer";
- }
- if (this.truncate) {
- if (this.truncate.length && this.truncate.length < match.getAnchorText().length) {
- attrs['title'] = match.getAnchorHref();
- }
- }
- return attrs;
- };
-
- AnchorTagBuilder.prototype.createCssClass = function (match) {
- var className = this.className;
- if (!className) {
- return "";
- }
- else {
- var returnClasses = [className], cssClassSuffixes = match.getCssClassSuffixes();
- for (var i = 0, len = cssClassSuffixes.length; i < len; i++) {
- returnClasses.push(className + '-' + cssClassSuffixes[i]);
- }
- return returnClasses.join(' ');
- }
- };
-
- AnchorTagBuilder.prototype.processAnchorText = function (anchorText) {
- anchorText = this.doTruncate(anchorText);
- return anchorText;
- };
-
- AnchorTagBuilder.prototype.doTruncate = function (anchorText) {
- var truncate = this.truncate;
- if (!truncate || !truncate.length)
- return anchorText;
- var truncateLength = truncate.length, truncateLocation = truncate.location;
- if (truncateLocation === 'smart') {
- return truncateSmart(anchorText, truncateLength);
- }
- else if (truncateLocation === 'middle') {
- return truncateMiddle(anchorText, truncateLength);
- }
- else {
- return truncateEnd(anchorText, truncateLength);
- }
- };
- return AnchorTagBuilder;
- }());
-
- var Match = (function () {
-
- function Match(cfg) {
-
- this.__jsduckDummyDocProp = null;
-
- this.matchedText = '';
-
- this.offset = 0;
- this.tagBuilder = cfg.tagBuilder;
- this.matchedText = cfg.matchedText;
- this.offset = cfg.offset;
- }
-
- Match.prototype.getMatchedText = function () {
- return this.matchedText;
- };
-
- Match.prototype.setOffset = function (offset) {
- this.offset = offset;
- };
-
- Match.prototype.getOffset = function () {
- return this.offset;
- };
-
- Match.prototype.getCssClassSuffixes = function () {
- return [this.getType()];
- };
-
- Match.prototype.buildTag = function () {
- return this.tagBuilder.build(this);
- };
- return Match;
- }());
-
-
- var extendStatics = function(d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- function __extends(d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- }
- var __assign = function() {
- __assign = Object.assign || function __assign(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
-
- var EmailMatch = (function (_super) {
- __extends(EmailMatch, _super);
-
- function EmailMatch(cfg) {
- var _this = _super.call(this, cfg) || this;
-
- _this.email = '';
- _this.email = cfg.email;
- return _this;
- }
-
- EmailMatch.prototype.getType = function () {
- return 'email';
- };
-
- EmailMatch.prototype.getEmail = function () {
- return this.email;
- };
-
- EmailMatch.prototype.getAnchorHref = function () {
- return 'mailto:' + this.email;
- };
-
- EmailMatch.prototype.getAnchorText = function () {
- return this.email;
- };
- return EmailMatch;
- }(Match));
-
- var HashtagMatch = (function (_super) {
- __extends(HashtagMatch, _super);
-
- function HashtagMatch(cfg) {
- var _this = _super.call(this, cfg) || this;
-
- _this.serviceName = '';
-
- _this.hashtag = '';
- _this.serviceName = cfg.serviceName;
- _this.hashtag = cfg.hashtag;
- return _this;
- }
-
- HashtagMatch.prototype.getType = function () {
- return 'hashtag';
- };
-
- HashtagMatch.prototype.getServiceName = function () {
- return this.serviceName;
- };
-
- HashtagMatch.prototype.getHashtag = function () {
- return this.hashtag;
- };
-
- HashtagMatch.prototype.getAnchorHref = function () {
- var serviceName = this.serviceName, hashtag = this.hashtag;
- switch (serviceName) {
- case 'twitter':
- return 'https://twitter.com/hashtag/' + hashtag;
- case 'facebook':
- return 'https://www.facebook.com/hashtag/' + hashtag;
- case 'instagram':
- return 'https://instagram.com/explore/tags/' + hashtag;
- default:
- throw new Error('Unknown service name to point hashtag to: ' + serviceName);
- }
- };
-
- HashtagMatch.prototype.getAnchorText = function () {
- return '#' + this.hashtag;
- };
- return HashtagMatch;
- }(Match));
-
- var MentionMatch = (function (_super) {
- __extends(MentionMatch, _super);
-
- function MentionMatch(cfg) {
- var _this = _super.call(this, cfg) || this;
-
- _this.serviceName = 'twitter';
-
- _this.mention = '';
- _this.mention = cfg.mention;
- _this.serviceName = cfg.serviceName;
- return _this;
- }
-
- MentionMatch.prototype.getType = function () {
- return 'mention';
- };
-
- MentionMatch.prototype.getMention = function () {
- return this.mention;
- };
-
- MentionMatch.prototype.getServiceName = function () {
- return this.serviceName;
- };
-
- MentionMatch.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);
- }
- };
-
- MentionMatch.prototype.getAnchorText = function () {
- return '@' + this.mention;
- };
-
- MentionMatch.prototype.getCssClassSuffixes = function () {
- var cssClassSuffixes = _super.prototype.getCssClassSuffixes.call(this), serviceName = this.getServiceName();
- if (serviceName) {
- cssClassSuffixes.push(serviceName);
- }
- return cssClassSuffixes;
- };
- return MentionMatch;
- }(Match));
-
- var PhoneMatch = (function (_super) {
- __extends(PhoneMatch, _super);
-
- function PhoneMatch(cfg) {
- var _this = _super.call(this, cfg) || this;
-
- _this.number = '';
-
- _this.plusSign = false;
- _this.number = cfg.number;
- _this.plusSign = cfg.plusSign;
- return _this;
- }
-
- PhoneMatch.prototype.getType = function () {
- return 'phone';
- };
-
- PhoneMatch.prototype.getPhoneNumber = function () {
- return this.number;
- };
-
- PhoneMatch.prototype.getNumber = function () {
- return this.getPhoneNumber();
- };
-
- PhoneMatch.prototype.getAnchorHref = function () {
- return 'tel:' + (this.plusSign ? '+' : '') + this.number;
- };
-
- PhoneMatch.prototype.getAnchorText = function () {
- return this.matchedText;
- };
- return PhoneMatch;
- }(Match));
-
- var UrlMatch = (function (_super) {
- __extends(UrlMatch, _super);
-
- function UrlMatch(cfg) {
- var _this = _super.call(this, cfg) || this;
-
- _this.url = '';
-
- _this.urlMatchType = 'scheme';
-
- _this.protocolUrlMatch = false;
-
- _this.protocolRelativeMatch = false;
-
- _this.stripPrefix = { scheme: true, www: true };
-
- _this.stripTrailingSlash = true;
-
- _this.decodePercentEncoding = true;
-
- _this.schemePrefixRegex = /^(https?:\/\/)?/i;
-
- _this.wwwPrefixRegex = /^(https?:\/\/)?(www\.)?/i;
-
- _this.protocolRelativeRegex = /^\/\//;
-
- _this.protocolPrepended = false;
- _this.urlMatchType = cfg.urlMatchType;
- _this.url = cfg.url;
- _this.protocolUrlMatch = cfg.protocolUrlMatch;
- _this.protocolRelativeMatch = cfg.protocolRelativeMatch;
- _this.stripPrefix = cfg.stripPrefix;
- _this.stripTrailingSlash = cfg.stripTrailingSlash;
- _this.decodePercentEncoding = cfg.decodePercentEncoding;
- return _this;
- }
-
- UrlMatch.prototype.getType = function () {
- return 'url';
- };
-
- UrlMatch.prototype.getUrlMatchType = function () {
- return this.urlMatchType;
- };
-
- UrlMatch.prototype.getUrl = function () {
- var url = this.url;
-
- if (!this.protocolRelativeMatch && !this.protocolUrlMatch && !this.protocolPrepended) {
- url = this.url = 'http://' + url;
- this.protocolPrepended = true;
- }
- return url;
- };
-
- UrlMatch.prototype.getAnchorHref = function () {
- var url = this.getUrl();
- return url.replace(/&/g, '&');
- };
-
- UrlMatch.prototype.getAnchorText = function () {
- var anchorText = this.getMatchedText();
- if (this.protocolRelativeMatch) {
-
- anchorText = this.stripProtocolRelativePrefix(anchorText);
- }
- if (this.stripPrefix.scheme) {
- anchorText = this.stripSchemePrefix(anchorText);
- }
- if (this.stripPrefix.www) {
- anchorText = this.stripWwwPrefix(anchorText);
- }
- if (this.stripTrailingSlash) {
- anchorText = this.removeTrailingSlash(anchorText);
- }
- if (this.decodePercentEncoding) {
- anchorText = this.removePercentEncoding(anchorText);
- }
- return anchorText;
- };
-
-
-
- UrlMatch.prototype.stripSchemePrefix = function (url) {
- return url.replace(this.schemePrefixRegex, '');
- };
-
- UrlMatch.prototype.stripWwwPrefix = function (url) {
- return url.replace(this.wwwPrefixRegex, '$1');
- };
-
- UrlMatch.prototype.stripProtocolRelativePrefix = function (text) {
- return text.replace(this.protocolRelativeRegex, '');
- };
-
- UrlMatch.prototype.removeTrailingSlash = function (anchorText) {
- if (anchorText.charAt(anchorText.length - 1) === '/') {
- anchorText = anchorText.slice(0, -1);
- }
- return anchorText;
- };
-
- UrlMatch.prototype.removePercentEncoding = function (anchorText) {
-
-
-
- var preProcessedEntityAnchorText = anchorText
- .replace(/%22/gi, '"')
- .replace(/%26/gi, '&')
- .replace(/%27/gi, ''')
- .replace(/%3C/gi, '<')
- .replace(/%3E/gi, '>');
- try {
-
- return decodeURIComponent(preProcessedEntityAnchorText);
- }
- catch (e) {
- return preProcessedEntityAnchorText;
- }
- };
- return UrlMatch;
- }(Match));
-
- var Matcher = (function () {
-
- function Matcher(cfg) {
-
- this.__jsduckDummyDocProp = null;
- this.tagBuilder = cfg.tagBuilder;
- }
- return Matcher;
- }());
-
-
- var letterRe = /[A-Za-z]/;
-
- var digitRe = /[0-9]/;
-
- var whitespaceRe = /\s/;
-
- var quoteRe = /['"]/;
-
- var controlCharsRe = /[\x00-\x1F\x7F]/;
-
- var alphaCharsStr = /A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC/
- .source;
-
- var emojiStr = /\u00a9\u00ae\u2000-\u3300\ud83c\ud000-\udfff\ud83d\ud000-\udfff\ud83e\ud000-\udfff/
- .source;
-
- var marksStr = /\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D4-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C03\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D01-\u0D03\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF8\u1CF9\u1DC0-\u1DF5\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F/
- .source;
-
- var alphaCharsAndMarksStr = alphaCharsStr + emojiStr + marksStr;
-
- var decimalNumbersStr = /0-9\u0660-\u0669\u06F0-\u06F9\u07C0-\u07C9\u0966-\u096F\u09E6-\u09EF\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0BE6-\u0BEF\u0C66-\u0C6F\u0CE6-\u0CEF\u0D66-\u0D6F\u0DE6-\u0DEF\u0E50-\u0E59\u0ED0-\u0ED9\u0F20-\u0F29\u1040-\u1049\u1090-\u1099\u17E0-\u17E9\u1810-\u1819\u1946-\u194F\u19D0-\u19D9\u1A80-\u1A89\u1A90-\u1A99\u1B50-\u1B59\u1BB0-\u1BB9\u1C40-\u1C49\u1C50-\u1C59\uA620-\uA629\uA8D0-\uA8D9\uA900-\uA909\uA9D0-\uA9D9\uA9F0-\uA9F9\uAA50-\uAA59\uABF0-\uABF9\uFF10-\uFF19/
- .source;
-
- var alphaNumericCharsStr = alphaCharsAndMarksStr + decimalNumbersStr;
-
- var alphaNumericAndMarksCharsStr = alphaCharsAndMarksStr + decimalNumbersStr;
-
- var ipStr = '(?:[' + decimalNumbersStr + ']{1,3}\\.){3}[' + decimalNumbersStr + ']{1,3}';
-
- var domainLabelStr = '[' + alphaNumericAndMarksCharsStr + '](?:[' + alphaNumericAndMarksCharsStr + '\\-]{0,61}[' + alphaNumericAndMarksCharsStr + '])?';
- var getDomainLabelStr = function (group) {
- return '(?=(' + domainLabelStr + '))\\' + group;
- };
-
- var getDomainNameStr = function (group) {
- return '(?:' + getDomainLabelStr(group) + '(?:\\.' + getDomainLabelStr(group + 1) + '){0,126}|' + ipStr + ')';
- };
-
- var domainNameCharRegex = new RegExp("[" + alphaNumericAndMarksCharsStr + "]");
-
-
- var tldRegex = /(?:xn--vermgensberatung-pwb|xn--vermgensberater-ctb|xn--clchc0ea0b2g2a9gcd|xn--w4r85el8fhu5dnra|northwesternmutual|travelersinsurance|vermögensberatung|xn--3oq18vl8pn36a|xn--5su34j936bgsg|xn--bck1b9a5dre4c|xn--mgbai9azgqp6j|xn--mgberp4a5d4ar|xn--xkc2dl3a5ee0h|vermögensberater|xn--fzys8d69uvgm|xn--mgba7c0bbn0a|xn--xkc2al3hye2a|americanexpress|kerryproperties|sandvikcoromant|xn--i1b6b1a6a2e|xn--kcrx77d1x4a|xn--lgbbat1ad8j|xn--mgba3a4f16a|xn--mgbaakc7dvf|xn--mgbc0a9azcg|xn--nqv7fs00ema|afamilycompany|americanfamily|bananarepublic|cancerresearch|cookingchannel|kerrylogistics|weatherchannel|xn--54b7fta0cc|xn--6qq986b3xl|xn--80aqecdr1a|xn--b4w605ferd|xn--fiq228c5hs|xn--h2breg3eve|xn--jlq61u9w7b|xn--mgba3a3ejt|xn--mgbaam7a8h|xn--mgbayh7gpa|xn--mgbb9fbpob|xn--mgbbh1a71e|xn--mgbca7dzdo|xn--mgbi4ecexp|xn--mgbx4cd0ab|xn--rvc1e0am3e|international|lifeinsurance|spreadbetting|travelchannel|wolterskluwer|xn--eckvdtc9d|xn--fpcrj9c3d|xn--fzc2c9e2c|xn--h2brj9c8c|xn--tiq49xqyj|xn--yfro4i67o|xn--ygbi2ammx|construction|lplfinancial|scholarships|versicherung|xn--3e0b707e|xn--45br5cyl|xn--80adxhks|xn--80asehdb|xn--8y0a063a|xn--gckr3f0f|xn--mgb9awbf|xn--mgbab2bd|xn--mgbgu82a|xn--mgbpl2fh|xn--mgbt3dhd|xn--mk1bu44c|xn--ngbc5azd|xn--ngbe9e0a|xn--ogbpf8fl|xn--qcka1pmc|accountants|barclaycard|blackfriday|blockbuster|bridgestone|calvinklein|contractors|creditunion|engineering|enterprises|foodnetwork|investments|kerryhotels|lamborghini|motorcycles|olayangroup|photography|playstation|productions|progressive|redumbrella|rightathome|williamhill|xn--11b4c3d|xn--1ck2e1b|xn--1qqw23a|xn--2scrj9c|xn--3bst00m|xn--3ds443g|xn--3hcrj9c|xn--42c2d9a|xn--45brj9c|xn--55qw42g|xn--6frz82g|xn--80ao21a|xn--9krt00a|xn--cck2b3b|xn--czr694b|xn--d1acj3b|xn--efvy88h|xn--estv75g|xn--fct429k|xn--fjq720a|xn--flw351e|xn--g2xx48c|xn--gecrj9c|xn--gk3at1e|xn--h2brj9c|xn--hxt814e|xn--imr513n|xn--j6w193g|xn--jvr189m|xn--kprw13d|xn--kpry57d|xn--kpu716f|xn--mgbbh1a|xn--mgbtx2b|xn--mix891f|xn--nyqy26a|xn--otu796d|xn--pbt977c|xn--pgbs0dh|xn--q9jyb4c|xn--rhqv96g|xn--rovu88b|xn--s9brj9c|xn--ses554g|xn--t60b56a|xn--vuq861b|xn--w4rs40l|xn--xhq521b|xn--zfr164b|சிங்கப்பூர்|accountant|apartments|associates|basketball|bnpparibas|boehringer|capitalone|consulting|creditcard|cuisinella|eurovision|extraspace|foundation|healthcare|immobilien|industries|management|mitsubishi|nationwide|newholland|nextdirect|onyourside|properties|protection|prudential|realestate|republican|restaurant|schaeffler|swiftcover|tatamotors|technology|telefonica|university|vistaprint|vlaanderen|volkswagen|xn--30rr7y|xn--3pxu8k|xn--45q11c|xn--4gbrim|xn--55qx5d|xn--5tzm5g|xn--80aswg|xn--90a3ac|xn--9dbq2a|xn--9et52u|xn--c2br7g|xn--cg4bki|xn--czrs0t|xn--czru2d|xn--fiq64b|xn--fiqs8s|xn--fiqz9s|xn--io0a7i|xn--kput3i|xn--mxtq1m|xn--o3cw4h|xn--pssy2u|xn--unup4y|xn--wgbh1c|xn--wgbl6a|xn--y9a3aq|accenture|alfaromeo|allfinanz|amsterdam|analytics|aquarelle|barcelona|bloomberg|christmas|community|directory|education|equipment|fairwinds|financial|firestone|fresenius|frontdoor|fujixerox|furniture|goldpoint|hisamitsu|homedepot|homegoods|homesense|honeywell|institute|insurance|kuokgroup|ladbrokes|lancaster|landrover|lifestyle|marketing|marshalls|melbourne|microsoft|panasonic|passagens|pramerica|richardli|scjohnson|shangrila|solutions|statebank|statefarm|stockholm|travelers|vacations|xn--90ais|xn--c1avg|xn--d1alf|xn--e1a4c|xn--fhbei|xn--j1aef|xn--j1amh|xn--l1acc|xn--ngbrx|xn--nqv7f|xn--p1acf|xn--tckwe|xn--vhquv|yodobashi|abudhabi|airforce|allstate|attorney|barclays|barefoot|bargains|baseball|boutique|bradesco|broadway|brussels|budapest|builders|business|capetown|catering|catholic|chrysler|cipriani|cityeats|cleaning|clinique|clothing|commbank|computer|delivery|deloitte|democrat|diamonds|discount|discover|download|engineer|ericsson|esurance|etisalat|everbank|exchange|feedback|fidelity|firmdale|football|frontier|goodyear|grainger|graphics|guardian|hdfcbank|helsinki|holdings|hospital|infiniti|ipiranga|istanbul|jpmorgan|lighting|lundbeck|marriott|maserati|mckinsey|memorial|merckmsd|mortgage|movistar|observer|partners|pharmacy|pictures|plumbing|property|redstone|reliance|saarland|samsclub|security|services|shopping|showtime|softbank|software|stcgroup|supplies|symantec|training|uconnect|vanguard|ventures|verisign|woodside|xn--90ae|xn--node|xn--p1ai|xn--qxam|yokohama|السعودية|abogado|academy|agakhan|alibaba|android|athleta|auction|audible|auspost|avianca|banamex|bauhaus|bentley|bestbuy|booking|brother|bugatti|capital|caravan|careers|cartier|channel|charity|chintai|citadel|clubmed|college|cologne|comcast|company|compare|contact|cooking|corsica|country|coupons|courses|cricket|cruises|dentist|digital|domains|exposed|express|farmers|fashion|ferrari|ferrero|finance|fishing|fitness|flights|florist|flowers|forsale|frogans|fujitsu|gallery|genting|godaddy|grocery|guitars|hamburg|hangout|hitachi|holiday|hosting|hoteles|hotmail|hyundai|iselect|ismaili|jewelry|juniper|kitchen|komatsu|lacaixa|lancome|lanxess|lasalle|latrobe|leclerc|liaison|limited|lincoln|markets|metlife|monster|netbank|netflix|network|neustar|okinawa|oldnavy|organic|origins|philips|pioneer|politie|realtor|recipes|rentals|reviews|rexroth|samsung|sandvik|schmidt|schwarz|science|shiksha|shriram|singles|staples|starhub|storage|support|surgery|systems|temasek|theater|theatre|tickets|tiffany|toshiba|trading|walmart|wanggou|watches|weather|website|wedding|whoswho|windows|winners|xfinity|yamaxun|youtube|zuerich|католик|اتصالات|الجزائر|العليان|پاکستان|كاثوليك|موبايلي|இந்தியா|abarth|abbott|abbvie|active|africa|agency|airbus|airtel|alipay|alsace|alstom|anquan|aramco|author|bayern|beauty|berlin|bharti|blanco|bostik|boston|broker|camera|career|caseih|casino|center|chanel|chrome|church|circle|claims|clinic|coffee|comsec|condos|coupon|credit|cruise|dating|datsun|dealer|degree|dental|design|direct|doctor|dunlop|dupont|durban|emerck|energy|estate|events|expert|family|flickr|futbol|gallup|garden|george|giving|global|google|gratis|health|hermes|hiphop|hockey|hotels|hughes|imamat|insure|intuit|jaguar|joburg|juegos|kaufen|kinder|kindle|kosher|lancia|latino|lawyer|lefrak|living|locker|london|luxury|madrid|maison|makeup|market|mattel|mobile|mobily|monash|mormon|moscow|museum|mutual|nagoya|natura|nissan|nissay|norton|nowruz|office|olayan|online|oracle|orange|otsuka|pfizer|photos|physio|piaget|pictet|quebec|racing|realty|reisen|repair|report|review|rocher|rogers|ryukyu|safety|sakura|sanofi|school|schule|search|secure|select|shouji|soccer|social|stream|studio|supply|suzuki|swatch|sydney|taipei|taobao|target|tattoo|tennis|tienda|tjmaxx|tkmaxx|toyota|travel|unicom|viajes|viking|villas|virgin|vision|voting|voyage|vuelos|walter|warman|webcam|xihuan|yachts|yandex|zappos|москва|онлайн|ابوظبي|ارامكو|الاردن|المغرب|امارات|فلسطين|مليسيا|भारतम्|இலங்கை|ファッション|actor|adult|aetna|amfam|amica|apple|archi|audio|autos|azure|baidu|beats|bible|bingo|black|boats|bosch|build|canon|cards|chase|cheap|cisco|citic|click|cloud|coach|codes|crown|cymru|dabur|dance|deals|delta|dodge|drive|dubai|earth|edeka|email|epost|epson|faith|fedex|final|forex|forum|gallo|games|gifts|gives|glade|glass|globo|gmail|green|gripe|group|gucci|guide|homes|honda|horse|house|hyatt|ikano|intel|irish|iveco|jetzt|koeln|kyoto|lamer|lease|legal|lexus|lilly|linde|lipsy|lixil|loans|locus|lotte|lotto|lupin|macys|mango|media|miami|money|mopar|movie|nadex|nexus|nikon|ninja|nokia|nowtv|omega|osaka|paris|parts|party|phone|photo|pizza|place|poker|praxi|press|prime|promo|quest|radio|rehab|reise|ricoh|rocks|rodeo|rugby|salon|sener|seven|sharp|shell|shoes|skype|sling|smart|smile|solar|space|sport|stada|store|study|style|sucks|swiss|tatar|tires|tirol|tmall|today|tokyo|tools|toray|total|tours|trade|trust|tunes|tushu|ubank|vegas|video|vodka|volvo|wales|watch|weber|weibo|works|world|xerox|yahoo|zippo|ایران|بازار|بھارت|سودان|سورية|همراه|भारोत|संगठन|বাংলা|భారత్|ഭാരതം|嘉里大酒店|aarp|able|adac|aero|aigo|akdn|ally|amex|arab|army|arpa|arte|asda|asia|audi|auto|baby|band|bank|bbva|beer|best|bike|bing|blog|blue|bofa|bond|book|buzz|cafe|call|camp|care|cars|casa|case|cash|cbre|cern|chat|citi|city|club|cool|coop|cyou|data|date|dclk|deal|dell|desi|diet|dish|docs|doha|duck|duns|dvag|erni|fage|fail|fans|farm|fast|fiat|fido|film|fire|fish|flir|food|ford|free|fund|game|gbiz|gent|ggee|gift|gmbh|gold|golf|goog|guge|guru|hair|haus|hdfc|help|here|hgtv|host|hsbc|icbc|ieee|imdb|immo|info|itau|java|jeep|jobs|jprs|kddi|kiwi|kpmg|kred|land|lego|lgbt|lidl|life|like|limo|link|live|loan|loft|love|ltda|luxe|maif|meet|meme|menu|mini|mint|mobi|moda|moto|name|navy|news|next|nico|nike|ollo|open|page|pars|pccw|pics|ping|pink|play|plus|pohl|porn|post|prod|prof|qpon|raid|read|reit|rent|rest|rich|rmit|room|rsvp|ruhr|safe|sale|sarl|save|saxo|scor|scot|seat|seek|sexy|shaw|shia|shop|show|silk|sina|site|skin|sncf|sohu|song|sony|spot|star|surf|talk|taxi|team|tech|teva|tiaa|tips|town|toys|tube|vana|visa|viva|vivo|vote|voto|wang|weir|wien|wiki|wine|work|xbox|yoga|zara|zero|zone|дети|сайт|بارت|بيتك|ڀارت|تونس|شبكة|عراق|عمان|موقع|भारत|ভারত|ভাৰত|ਭਾਰਤ|ભારત|ଭାରତ|ಭಾರತ|ලංකා|グーグル|クラウド|ポイント|大众汽车|组织机构|電訊盈科|香格里拉|aaa|abb|abc|aco|ads|aeg|afl|aig|anz|aol|app|art|aws|axa|bar|bbc|bbt|bcg|bcn|bet|bid|bio|biz|bms|bmw|bnl|bom|boo|bot|box|buy|bzh|cab|cal|cam|car|cat|cba|cbn|cbs|ceb|ceo|cfa|cfd|com|crs|csc|dad|day|dds|dev|dhl|diy|dnp|dog|dot|dtv|dvr|eat|eco|edu|esq|eus|fan|fit|fly|foo|fox|frl|ftr|fun|fyi|gal|gap|gdn|gea|gle|gmo|gmx|goo|gop|got|gov|hbo|hiv|hkt|hot|how|ibm|ice|icu|ifm|inc|ing|ink|int|ist|itv|jcb|jcp|jio|jll|jmp|jnj|jot|joy|kfh|kia|kim|kpn|krd|lat|law|lds|llc|lol|lpl|ltd|man|map|mba|med|men|mil|mit|mlb|mls|mma|moe|moi|mom|mov|msd|mtn|mtr|nab|nba|nec|net|new|nfl|ngo|nhk|now|nra|nrw|ntt|nyc|obi|off|one|ong|onl|ooo|org|ott|ovh|pay|pet|phd|pid|pin|pnc|pro|pru|pub|pwc|qvc|red|ren|ril|rio|rip|run|rwe|sap|sas|sbi|sbs|sca|scb|ses|sew|sex|sfr|ski|sky|soy|srl|srt|stc|tab|tax|tci|tdk|tel|thd|tjx|top|trv|tui|tvs|ubs|uno|uol|ups|vet|vig|vin|vip|wed|win|wme|wow|wtc|wtf|xin|xxx|xyz|you|yun|zip|бел|ком|қаз|мкд|мон|орг|рус|срб|укр|հայ|קום|عرب|قطر|كوم|مصر|कॉम|नेट|คอม|ไทย|ストア|セール|みんな|中文网|天主教|我爱你|新加坡|淡马锡|诺基亚|飞利浦|ac|ad|ae|af|ag|ai|al|am|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|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|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|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|tf|tg|th|tj|tk|tl|tm|tn|to|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw|ελ|бг|ею|рф|გე|닷넷|닷컴|삼성|한국|コム|世界|中信|中国|中國|企业|佛山|信息|健康|八卦|公司|公益|台湾|台灣|商城|商店|商标|嘉里|在线|大拿|娱乐|家電|工行|广东|微博|慈善|手机|手表|招聘|政务|政府|新闻|时尚|書籍|机构|游戏|澳門|点看|珠宝|移动|网址|网店|网站|网络|联通|谷歌|购物|通販|集团|食品|餐厅|香港)/;
-
-
-
- var EmailMatcher = (function (_super) {
- __extends(EmailMatcher, _super);
- function EmailMatcher() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
-
- _this.localPartCharRegex = new RegExp("[" + alphaNumericAndMarksCharsStr + "!#$%&'*+/=?^_`{|}~-]");
-
- _this.strictTldRegex = new RegExp("^" + tldRegex.source + "$");
- return _this;
- }
-
- EmailMatcher.prototype.parseMatches = function (text) {
- var tagBuilder = this.tagBuilder, localPartCharRegex = this.localPartCharRegex, strictTldRegex = this.strictTldRegex, matches = [], len = text.length, noCurrentEmailMatch = new CurrentEmailMatch();
-
- var mailtoTransitions = {
- 'm': 'a',
- 'a': 'i',
- 'i': 'l',
- 'l': 't',
- 't': 'o',
- 'o': ':',
- };
- var charIdx = 0, state = 0 , currentEmailMatch = noCurrentEmailMatch;
-
-
-
-
- while (charIdx < len) {
- var char = text.charAt(charIdx);
-
-
-
-
- switch (state) {
- case 0 :
- stateNonEmailAddress(char);
- break;
- case 1 :
- stateMailTo(text.charAt(charIdx - 1), char);
- break;
- case 2 :
- stateLocalPart(char);
- break;
- case 3 :
- stateLocalPartDot(char);
- break;
- case 4 :
- stateAtSign(char);
- break;
- case 5 :
- stateDomainChar(char);
- break;
- case 6 :
- stateDomainHyphen(char);
- break;
- case 7 :
- stateDomainDot(char);
- break;
- default:
- throwUnhandledCaseError(state);
- }
-
-
-
-
- charIdx++;
- }
-
- captureMatchIfValidAndReset();
-
-
- return matches;
-
- function stateNonEmailAddress(char) {
- if (char === 'm') {
- beginEmailMatch(1 );
- }
- else if (localPartCharRegex.test(char)) {
- beginEmailMatch();
- }
- }
-
- function stateMailTo(prevChar, char) {
- if (prevChar === ':') {
-
- if (localPartCharRegex.test(char)) {
- state = 2 ;
- currentEmailMatch = new CurrentEmailMatch(__assign({}, currentEmailMatch, { hasMailtoPrefix: true }));
- }
- else {
-
-
-
- resetToNonEmailMatchState();
- }
- }
- else if (mailtoTransitions[prevChar] === char) ;
- else if (localPartCharRegex.test(char)) {
-
-
- state = 2 ;
- }
- else if (char === '.') {
-
-
- state = 3 ;
- }
- else if (char === '@') {
-
-
- state = 4 ;
- }
- else {
-
- resetToNonEmailMatchState();
- }
- }
-
-
- function stateLocalPart(char) {
- if (char === '.') {
- state = 3 ;
- }
- else if (char === '@') {
- state = 4 ;
- }
- else if (localPartCharRegex.test(char)) ;
- else {
-
- resetToNonEmailMatchState();
- }
- }
-
- function stateLocalPartDot(char) {
- if (char === '.') {
-
-
- resetToNonEmailMatchState();
- }
- else if (char === '@') {
-
-
- resetToNonEmailMatchState();
- }
- else if (localPartCharRegex.test(char)) {
- state = 2 ;
- }
- else {
-
- resetToNonEmailMatchState();
- }
- }
- function stateAtSign(char) {
- if (domainNameCharRegex.test(char)) {
- state = 5 ;
- }
- else {
-
- resetToNonEmailMatchState();
- }
- }
- function stateDomainChar(char) {
- if (char === '.') {
- state = 7 ;
- }
- else if (char === '-') {
- state = 6 ;
- }
- else if (domainNameCharRegex.test(char)) ;
- else {
-
-
- captureMatchIfValidAndReset();
- }
- }
- function stateDomainHyphen(char) {
- if (char === '-' || char === '.') {
-
- captureMatchIfValidAndReset();
- }
- else if (domainNameCharRegex.test(char)) {
- state = 5 ;
- }
- else {
-
- captureMatchIfValidAndReset();
- }
- }
- function stateDomainDot(char) {
- if (char === '.' || char === '-') {
-
- captureMatchIfValidAndReset();
- }
- else if (domainNameCharRegex.test(char)) {
- state = 5 ;
-
-
-
-
- currentEmailMatch = new CurrentEmailMatch(__assign({}, currentEmailMatch, { hasDomainDot: true }));
- }
- else {
-
- captureMatchIfValidAndReset();
- }
- }
- function beginEmailMatch(newState) {
- if (newState === void 0) { newState = 2 ; }
- state = newState;
- currentEmailMatch = new CurrentEmailMatch({ idx: charIdx });
- }
- function resetToNonEmailMatchState() {
- state = 0 ;
- currentEmailMatch = noCurrentEmailMatch;
- }
-
- function captureMatchIfValidAndReset() {
- if (currentEmailMatch.hasDomainDot) {
- var matchedText = text.slice(currentEmailMatch.idx, charIdx);
-
-
-
-
- if (/[-.]$/.test(matchedText)) {
- matchedText = matchedText.slice(0, -1);
- }
- var emailAddress = currentEmailMatch.hasMailtoPrefix
- ? matchedText.slice('mailto:'.length)
- : matchedText;
-
- if (doesEmailHaveValidTld(emailAddress)) {
- matches.push(new EmailMatch({
- tagBuilder: tagBuilder,
- matchedText: matchedText,
- offset: currentEmailMatch.idx,
- email: emailAddress
- }));
- }
- }
- resetToNonEmailMatchState();
-
- function doesEmailHaveValidTld(emailAddress) {
- var emailAddressTld = emailAddress.split('.').pop() || '';
- var emailAddressNormalized = emailAddressTld.toLowerCase();
- var isValidTld = strictTldRegex.test(emailAddressNormalized);
- return isValidTld;
- }
- }
- };
- return EmailMatcher;
- }(Matcher));
- var CurrentEmailMatch = (function () {
- function CurrentEmailMatch(cfg) {
- if (cfg === void 0) { cfg = {}; }
- this.idx = cfg.idx !== undefined ? cfg.idx : -1;
- this.hasMailtoPrefix = !!cfg.hasMailtoPrefix;
- this.hasDomainDot = !!cfg.hasDomainDot;
- }
- return CurrentEmailMatch;
- }());
-
- var UrlMatchValidator = (function () {
- function UrlMatchValidator() {
- }
-
- UrlMatchValidator.isValid = function (urlMatch, protocolUrlMatch) {
- if ((protocolUrlMatch && !this.isValidUriScheme(protocolUrlMatch)) ||
- this.urlMatchDoesNotHaveProtocolOrDot(urlMatch, protocolUrlMatch) ||
- (this.urlMatchDoesNotHaveAtLeastOneWordChar(urlMatch, protocolUrlMatch) &&
- !this.isValidIpAddress(urlMatch)) ||
- this.containsMultipleDots(urlMatch)) {
- return false;
- }
- return true;
- };
- UrlMatchValidator.isValidIpAddress = function (uriSchemeMatch) {
- var newRegex = new RegExp(this.hasFullProtocolRegex.source + this.ipRegex.source);
- var uriScheme = uriSchemeMatch.match(newRegex);
- return uriScheme !== null;
- };
- UrlMatchValidator.containsMultipleDots = function (urlMatch) {
- var stringBeforeSlash = urlMatch;
- if (this.hasFullProtocolRegex.test(urlMatch)) {
- stringBeforeSlash = urlMatch.split('://')[1];
- }
- return stringBeforeSlash.split('/')[0].indexOf("..") > -1;
- };
-
- UrlMatchValidator.isValidUriScheme = function (uriSchemeMatch) {
- var uriSchemeMatchArr = uriSchemeMatch.match(this.uriSchemeRegex), uriScheme = uriSchemeMatchArr && uriSchemeMatchArr[0].toLowerCase();
- return (uriScheme !== 'javascript:' && uriScheme !== 'vbscript:');
- };
-
- UrlMatchValidator.urlMatchDoesNotHaveProtocolOrDot = function (urlMatch, protocolUrlMatch) {
- return (!!urlMatch && (!protocolUrlMatch || !this.hasFullProtocolRegex.test(protocolUrlMatch)) && urlMatch.indexOf('.') === -1);
- };
-
- UrlMatchValidator.urlMatchDoesNotHaveAtLeastOneWordChar = function (urlMatch, protocolUrlMatch) {
- if (urlMatch && protocolUrlMatch) {
- return !this.hasWordCharAfterProtocolRegex.test(urlMatch);
- }
- else {
- return false;
- }
- };
-
- UrlMatchValidator.hasFullProtocolRegex = /^[A-Za-z][-.+A-Za-z0-9]*:\/\//;
-
- UrlMatchValidator.uriSchemeRegex = /^[A-Za-z][-.+A-Za-z0-9]*:/;
-
- UrlMatchValidator.hasWordCharAfterProtocolRegex = new RegExp(":[^\\s]*?[" + alphaCharsStr + "]");
-
- UrlMatchValidator.ipRegex = /[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?(:[0-9]*)?\/?$/;
- return UrlMatchValidator;
- }());
-
- var UrlMatcher = (function (_super) {
- __extends(UrlMatcher, _super);
-
- function UrlMatcher(cfg) {
- var _this = _super.call(this, cfg) || this;
-
- _this.stripPrefix = { scheme: true, www: true };
-
- _this.stripTrailingSlash = true;
-
- _this.decodePercentEncoding = true;
-
- _this.matcherRegex = (function () {
- var schemeRegex = /(?:[A-Za-z][-.+A-Za-z0-9]{0,63}:(?![A-Za-z][-.+A-Za-z0-9]{0,63}:\/\/)(?!\d+\/?)(?:\/\/)?)/,
- wwwRegex = /(?:www\.)/,
-
-
- urlSuffixRegex = new RegExp('[/?#](?:[' + alphaNumericAndMarksCharsStr + '\\-+&@#/%=~_()|\'$*\\[\\]?!:,.;\u2713]*[' + alphaNumericAndMarksCharsStr + '\\-+&@#/%=~_()|\'$*\\[\\]\u2713])?');
- return new RegExp([
- '(?:',
- '(',
- schemeRegex.source,
- getDomainNameStr(2),
- ')',
- '|',
- '(',
- '(//)?',
- wwwRegex.source,
- getDomainNameStr(6),
- ')',
- '|',
- '(',
- '(//)?',
- getDomainNameStr(10) + '\\.',
- tldRegex.source,
- '(?![-' + alphaNumericCharsStr + '])',
- ')',
- ')',
- '(?::[0-9]+)?',
- '(?:' + urlSuffixRegex.source + ')?'
- ].join(""), 'gi');
- })();
-
- _this.wordCharRegExp = new RegExp('[' + alphaNumericAndMarksCharsStr + ']');
- _this.stripPrefix = cfg.stripPrefix;
- _this.stripTrailingSlash = cfg.stripTrailingSlash;
- _this.decodePercentEncoding = cfg.decodePercentEncoding;
- return _this;
- }
-
- UrlMatcher.prototype.parseMatches = function (text) {
- var matcherRegex = this.matcherRegex, stripPrefix = this.stripPrefix, stripTrailingSlash = this.stripTrailingSlash, decodePercentEncoding = this.decodePercentEncoding, tagBuilder = this.tagBuilder, matches = [], match;
- var _loop_1 = function () {
- var matchStr = match[0], schemeUrlMatch = match[1], wwwUrlMatch = match[4], wwwProtocolRelativeMatch = match[5],
-
- tldProtocolRelativeMatch = match[9], offset = match.index, protocolRelativeMatch = wwwProtocolRelativeMatch || tldProtocolRelativeMatch, prevChar = text.charAt(offset - 1);
- if (!UrlMatchValidator.isValid(matchStr, schemeUrlMatch)) {
- return "continue";
- }
-
-
- if (offset > 0 && prevChar === '@') {
- return "continue";
- }
-
-
-
-
- if (offset > 0 && protocolRelativeMatch && this_1.wordCharRegExp.test(prevChar)) {
- return "continue";
- }
-
-
-
- if (/\?$/.test(matchStr)) {
- matchStr = matchStr.substr(0, matchStr.length - 1);
- }
-
-
-
- if (this_1.matchHasUnbalancedClosingParen(matchStr)) {
- matchStr = matchStr.substr(0, matchStr.length - 1);
- }
- else {
-
- var pos = this_1.matchHasInvalidCharAfterTld(matchStr, schemeUrlMatch);
- if (pos > -1) {
- matchStr = matchStr.substr(0, pos);
- }
- }
-
-
-
-
-
- var foundCommonScheme = ['http://', 'https://'].find(function (commonScheme) { return !!schemeUrlMatch && schemeUrlMatch.indexOf(commonScheme) !== -1; });
- if (foundCommonScheme) {
-
-
-
- var indexOfSchemeStart = matchStr.indexOf(foundCommonScheme);
- matchStr = matchStr.substr(indexOfSchemeStart);
- schemeUrlMatch = schemeUrlMatch.substr(indexOfSchemeStart);
- offset = offset + indexOfSchemeStart;
- }
- var urlMatchType = schemeUrlMatch ? 'scheme' : (wwwUrlMatch ? 'www' : 'tld'), protocolUrlMatch = !!schemeUrlMatch;
- matches.push(new UrlMatch({
- tagBuilder: tagBuilder,
- matchedText: matchStr,
- offset: offset,
- urlMatchType: urlMatchType,
- url: matchStr,
- protocolUrlMatch: protocolUrlMatch,
- protocolRelativeMatch: !!protocolRelativeMatch,
- stripPrefix: stripPrefix,
- stripTrailingSlash: stripTrailingSlash,
- decodePercentEncoding: decodePercentEncoding,
- }));
- };
- var this_1 = this;
- while ((match = matcherRegex.exec(text)) !== null) {
- _loop_1();
- }
- return matches;
- };
-
- UrlMatcher.prototype.matchHasUnbalancedClosingParen = function (matchStr) {
- var endChar = matchStr.charAt(matchStr.length - 1);
- var startChar;
- if (endChar === ')') {
- startChar = '(';
- }
- else if (endChar === ']') {
- startChar = '[';
- }
- else {
- return false;
- }
-
-
-
- var numOpenBraces = 0;
- for (var i = 0, len = matchStr.length - 1; i < len; i++) {
- var char = matchStr.charAt(i);
- if (char === startChar) {
- numOpenBraces++;
- }
- else if (char === endChar) {
- numOpenBraces = Math.max(numOpenBraces - 1, 0);
- }
- }
-
-
-
-
-
- if (numOpenBraces === 0) {
- return true;
- }
- return false;
- };
-
- UrlMatcher.prototype.matchHasInvalidCharAfterTld = function (urlMatch, schemeUrlMatch) {
- if (!urlMatch) {
- return -1;
- }
- var offset = 0;
- if (schemeUrlMatch) {
- offset = urlMatch.indexOf(':');
- urlMatch = urlMatch.slice(offset);
- }
- var re = new RegExp("^((.?\/\/)?[-." + alphaNumericAndMarksCharsStr + "]*[-" + alphaNumericAndMarksCharsStr + "]\\.[-" + alphaNumericAndMarksCharsStr + "]+)");
- var res = re.exec(urlMatch);
- if (res === null) {
- return -1;
- }
- offset += res[1].length;
- urlMatch = urlMatch.slice(res[1].length);
- if (/^[^-.A-Za-z0-9:\/?#]/.test(urlMatch)) {
- return offset;
- }
- return -1;
- };
- return UrlMatcher;
- }(Matcher));
-
- var HashtagMatcher = (function (_super) {
- __extends(HashtagMatcher, _super);
-
- function HashtagMatcher(cfg) {
- var _this = _super.call(this, cfg) || this;
-
- _this.serviceName = 'twitter';
-
- _this.matcherRegex = new RegExp("#[_" + alphaNumericAndMarksCharsStr + "]{1,139}(?![_" + alphaNumericAndMarksCharsStr + "])", 'g');
-
- _this.nonWordCharRegex = new RegExp('[^' + alphaNumericAndMarksCharsStr + ']');
- _this.serviceName = cfg.serviceName;
- return _this;
- }
-
- HashtagMatcher.prototype.parseMatches = function (text) {
- var matcherRegex = this.matcherRegex, nonWordCharRegex = this.nonWordCharRegex, serviceName = this.serviceName, tagBuilder = this.tagBuilder, matches = [], match;
- while ((match = matcherRegex.exec(text)) !== null) {
- var offset = match.index, prevChar = text.charAt(offset - 1);
-
-
-
- if (offset === 0 || nonWordCharRegex.test(prevChar)) {
- var matchedText = match[0], hashtag = match[0].slice(1);
- matches.push(new HashtagMatch({
- tagBuilder: tagBuilder,
- matchedText: matchedText,
- offset: offset,
- serviceName: serviceName,
- hashtag: hashtag
- }));
- }
- }
- return matches;
- };
- return HashtagMatcher;
- }(Matcher));
-
- var PhoneMatcher = (function (_super) {
- __extends(PhoneMatcher, _super);
- function PhoneMatcher() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
-
- _this.matcherRegex = /(?:(?:(?:(\+)?\d{1,3}[-\040.]?)?\(?\d{3}\)?[-\040.]?\d{3}[-\040.]?\d{4})|(?:(\+)(?:9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)[-\040.]?(?:\d[-\040.]?){6,12}\d+))([,;]+[0-9]+#?)*/g;
- return _this;
- }
-
-
-
- PhoneMatcher.prototype.parseMatches = function (text) {
- var matcherRegex = this.matcherRegex, tagBuilder = this.tagBuilder, matches = [], match;
- while ((match = matcherRegex.exec(text)) !== null) {
-
- var matchedText = match[0], cleanNumber = matchedText.replace(/[^0-9,;#]/g, ''),
- plusSign = !!(match[1] || match[2]),
- before = match.index == 0 ? '' : text.substr(match.index - 1, 1), after = text.substr(match.index + matchedText.length, 1), contextClear = !before.match(/\d/) && !after.match(/\d/);
- if (this.testMatch(match[3]) && this.testMatch(matchedText) && contextClear) {
- matches.push(new PhoneMatch({
- tagBuilder: tagBuilder,
- matchedText: matchedText,
- offset: match.index,
- number: cleanNumber,
- plusSign: plusSign
- }));
- }
- }
- return matches;
- };
- PhoneMatcher.prototype.testMatch = function (text) {
- return /\D/.test(text);
- };
- return PhoneMatcher;
- }(Matcher));
-
- var MentionMatcher = (function (_super) {
- __extends(MentionMatcher, _super);
-
- function MentionMatcher(cfg) {
- var _this = _super.call(this, cfg) || this;
-
- _this.serviceName = 'twitter';
-
- _this.matcherRegexes = {
- 'twitter': new RegExp("@[_" + alphaNumericAndMarksCharsStr + "]{1,50}(?![_" + alphaNumericAndMarksCharsStr + "])", 'g'),
- 'instagram': new RegExp("@[_." + alphaNumericAndMarksCharsStr + "]{1,30}(?![_" + alphaNumericAndMarksCharsStr + "])", 'g'),
- 'soundcloud': new RegExp("@[-_." + alphaNumericAndMarksCharsStr + "]{1,50}(?![-_" + alphaNumericAndMarksCharsStr + "])", 'g')
- };
-
- _this.nonWordCharRegex = new RegExp('[^' + alphaNumericAndMarksCharsStr + ']');
- _this.serviceName = cfg.serviceName;
- return _this;
- }
-
- MentionMatcher.prototype.parseMatches = function (text) {
- var serviceName = this.serviceName, matcherRegex = this.matcherRegexes[this.serviceName], nonWordCharRegex = this.nonWordCharRegex, tagBuilder = this.tagBuilder, matches = [], match;
- if (!matcherRegex) {
- return matches;
- }
- while ((match = matcherRegex.exec(text)) !== null) {
- var offset = match.index, prevChar = text.charAt(offset - 1);
-
-
-
- if (offset === 0 || nonWordCharRegex.test(prevChar)) {
- var matchedText = match[0].replace(/\.+$/g, ''),
- mention = matchedText.slice(1);
- matches.push(new MentionMatch({
- tagBuilder: tagBuilder,
- matchedText: matchedText,
- offset: offset,
- serviceName: serviceName,
- mention: mention
- }));
- }
- }
- return matches;
- };
- return MentionMatcher;
- }(Matcher));
-
-
-
- function parseHtml(html, _a) {
- var onOpenTag = _a.onOpenTag, onCloseTag = _a.onCloseTag, onText = _a.onText, onComment = _a.onComment, onDoctype = _a.onDoctype;
- var noCurrentTag = new CurrentTag();
- var charIdx = 0, len = html.length, state = 0 , currentDataIdx = 0,
- currentTag = noCurrentTag;
-
-
-
-
- while (charIdx < len) {
- var char = html.charAt(charIdx);
-
-
-
-
-
- switch (state) {
- case 0 :
- stateData(char);
- break;
- case 1 :
- stateTagOpen(char);
- break;
- case 2 :
- stateEndTagOpen(char);
- break;
- case 3 :
- stateTagName(char);
- break;
- case 4 :
- stateBeforeAttributeName(char);
- break;
- case 5 :
- stateAttributeName(char);
- break;
- case 6 :
- stateAfterAttributeName(char);
- break;
- case 7 :
- stateBeforeAttributeValue(char);
- break;
- case 8 :
- stateAttributeValueDoubleQuoted(char);
- break;
- case 9 :
- stateAttributeValueSingleQuoted(char);
- break;
- case 10 :
- stateAttributeValueUnquoted(char);
- break;
- case 11 :
- stateAfterAttributeValueQuoted(char);
- break;
- case 12 :
- stateSelfClosingStartTag(char);
- break;
- case 13 :
- stateMarkupDeclarationOpen(char);
- break;
- case 14 :
- stateCommentStart(char);
- break;
- case 15 :
- stateCommentStartDash(char);
- break;
- case 16 :
- stateComment(char);
- break;
- case 17 :
- stateCommentEndDash(char);
- break;
- case 18 :
- stateCommentEnd(char);
- break;
- case 19 :
- stateCommentEndBang(char);
- break;
- case 20 :
- stateDoctype(char);
- break;
- default:
- throwUnhandledCaseError(state);
- }
-
-
-
-
-
- charIdx++;
- }
- if (currentDataIdx < charIdx) {
- emitText();
- }
-
-
-
-
- function stateData(char) {
- if (char === '<') {
- startNewTag();
- }
- }
-
-
- function stateTagOpen(char) {
- if (char === '!') {
- state = 13 ;
- }
- else if (char === '/') {
- state = 2 ;
- currentTag = new CurrentTag(__assign({}, currentTag, { isClosing: true }));
- }
- else if (char === '<') {
-
- startNewTag();
- }
- else if (letterRe.test(char)) {
-
- state = 3 ;
- currentTag = new CurrentTag(__assign({}, currentTag, { isOpening: true }));
- }
- else {
-
- state = 0 ;
- currentTag = noCurrentTag;
- }
- }
-
-
-
- function stateTagName(char) {
- if (whitespaceRe.test(char)) {
- currentTag = new CurrentTag(__assign({}, currentTag, { name: captureTagName() }));
- state = 4 ;
- }
- else if (char === '<') {
-
- startNewTag();
- }
- else if (char === '/') {
- currentTag = new CurrentTag(__assign({}, currentTag, { name: captureTagName() }));
- state = 12 ;
- }
- else if (char === '>') {
- currentTag = new CurrentTag(__assign({}, currentTag, { name: captureTagName() }));
- emitTagAndPreviousTextNode();
- }
- else if (!letterRe.test(char) && !digitRe.test(char) && char !== ':') {
-
-
- resetToDataState();
- }
- }
-
-
- function stateEndTagOpen(char) {
- if (char === '>') {
- resetToDataState();
- }
- else if (letterRe.test(char)) {
- state = 3 ;
- }
- else {
-
- resetToDataState();
- }
- }
-
- function stateBeforeAttributeName(char) {
- if (whitespaceRe.test(char)) ;
- else if (char === '/') {
- state = 12 ;
- }
- else if (char === '>') {
- emitTagAndPreviousTextNode();
- }
- else if (char === '<') {
-
- startNewTag();
- }
- else if (char === "=" || quoteRe.test(char) || controlCharsRe.test(char)) {
-
-
-
- resetToDataState();
- }
- else {
-
- state = 5 ;
- }
- }
-
- function stateAttributeName(char) {
- if (whitespaceRe.test(char)) {
- state = 6 ;
- }
- else if (char === '/') {
- state = 12 ;
- }
- else if (char === '=') {
- state = 7 ;
- }
- else if (char === '>') {
- emitTagAndPreviousTextNode();
- }
- else if (char === '<') {
-
- startNewTag();
- }
- else if (quoteRe.test(char)) {
-
-
-
- resetToDataState();
- }
- }
-
- function stateAfterAttributeName(char) {
- if (whitespaceRe.test(char)) ;
- else if (char === '/') {
- state = 12 ;
- }
- else if (char === '=') {
- state = 7 ;
- }
- else if (char === '>') {
- emitTagAndPreviousTextNode();
- }
- else if (char === '<') {
-
- startNewTag();
- }
- else if (quoteRe.test(char)) {
-
-
-
- resetToDataState();
- }
- else {
-
- state = 5 ;
- }
- }
-
- function stateBeforeAttributeValue(char) {
- if (whitespaceRe.test(char)) ;
- else if (char === "\"") {
- state = 8 ;
- }
- else if (char === "'") {
- state = 9 ;
- }
- else if (/[>=`]/.test(char)) {
-
-
- resetToDataState();
- }
- else if (char === '<') {
-
- startNewTag();
- }
- else {
-
- state = 10 ;
- }
- }
-
- function stateAttributeValueDoubleQuoted(char) {
- if (char === "\"") {
- state = 11 ;
- }
- }
-
- function stateAttributeValueSingleQuoted(char) {
- if (char === "'") {
- state = 11 ;
- }
- }
-
- function stateAttributeValueUnquoted(char) {
- if (whitespaceRe.test(char)) {
- state = 4 ;
- }
- else if (char === '>') {
- emitTagAndPreviousTextNode();
- }
- else if (char === '<') {
-
- startNewTag();
- }
- }
-
- function stateAfterAttributeValueQuoted(char) {
- if (whitespaceRe.test(char)) {
- state = 4 ;
- }
- else if (char === '/') {
- state = 12 ;
- }
- else if (char === '>') {
- emitTagAndPreviousTextNode();
- }
- else if (char === '<') {
-
- startNewTag();
- }
- else {
-
-
-
- state = 4 ;
- reconsumeCurrentCharacter();
- }
- }
-
-
-
- function stateSelfClosingStartTag(char) {
- if (char === '>') {
- currentTag = new CurrentTag(__assign({}, currentTag, { isClosing: true }));
- emitTagAndPreviousTextNode();
- }
- else {
- state = 4 ;
- }
- }
-
-
- function stateMarkupDeclarationOpen(char) {
- if (html.substr(charIdx, 2) === '--') {
- charIdx += 2;
- currentTag = new CurrentTag(__assign({}, currentTag, { type: 'comment' }));
- state = 14 ;
- }
- else if (html.substr(charIdx, 7).toUpperCase() === 'DOCTYPE') {
- charIdx += 7;
- currentTag = new CurrentTag(__assign({}, currentTag, { type: 'doctype' }));
- state = 20 ;
- }
- else {
-
-
-
-
-
- resetToDataState();
- }
- }
-
-
- function stateCommentStart(char) {
- if (char === '-') {
-
- state = 15 ;
- }
- else if (char === '>') {
-
-
-
- resetToDataState();
- }
- else {
-
- state = 16 ;
- }
- }
-
-
- function stateCommentStartDash(char) {
- if (char === '-') {
-
- state = 18 ;
- }
- else if (char === '>') {
-
-
-
- resetToDataState();
- }
- else {
-
- state = 16 ;
- }
- }
-
-
- function stateComment(char) {
- if (char === '-') {
- state = 17 ;
- }
- }
-
-
-
- function stateCommentEndDash(char) {
- if (char === '-') {
- state = 18 ;
- }
- else {
-
- state = 16 ;
- }
- }
-
-
-
- function stateCommentEnd(char) {
- if (char === '>') {
- emitTagAndPreviousTextNode();
- }
- else if (char === '!') {
- state = 19 ;
- }
- else if (char === '-') ;
- else {
-
-
- state = 16 ;
- }
- }
-
-
- function stateCommentEndBang(char) {
- if (char === '-') {
-
-
- state = 17 ;
- }
- else if (char === '>') {
-
- emitTagAndPreviousTextNode();
- }
- else {
-
-
- state = 16 ;
- }
- }
-
- function stateDoctype(char) {
- if (char === '>') {
- emitTagAndPreviousTextNode();
- }
- else if (char === '<') {
- startNewTag();
- }
- }
-
- function resetToDataState() {
- state = 0 ;
- currentTag = noCurrentTag;
- }
-
- function startNewTag() {
- state = 1 ;
- currentTag = new CurrentTag({ idx: charIdx });
- }
-
- function emitTagAndPreviousTextNode() {
- var textBeforeTag = html.slice(currentDataIdx, currentTag.idx);
- if (textBeforeTag) {
-
-
-
- onText(textBeforeTag, currentDataIdx);
- }
- if (currentTag.type === 'comment') {
- onComment(currentTag.idx);
- }
- else if (currentTag.type === 'doctype') {
- onDoctype(currentTag.idx);
- }
- else {
- if (currentTag.isOpening) {
- onOpenTag(currentTag.name, currentTag.idx);
- }
- if (currentTag.isClosing) {
- onCloseTag(currentTag.name, currentTag.idx);
- }
- }
-
- resetToDataState();
- currentDataIdx = charIdx + 1;
- }
- function emitText() {
- var text = html.slice(currentDataIdx, charIdx);
- onText(text, currentDataIdx);
- currentDataIdx = charIdx + 1;
- }
-
- function captureTagName() {
- var startIdx = currentTag.idx + (currentTag.isClosing ? 2 : 1);
- return html.slice(startIdx, charIdx).toLowerCase();
- }
-
- function reconsumeCurrentCharacter() {
- charIdx--;
- }
- }
- var CurrentTag = (function () {
- function CurrentTag(cfg) {
- if (cfg === void 0) { cfg = {}; }
- this.idx = cfg.idx !== undefined ? cfg.idx : -1;
- this.type = cfg.type || 'tag';
- this.name = cfg.name || '';
- this.isOpening = !!cfg.isOpening;
- this.isClosing = !!cfg.isClosing;
- }
- return CurrentTag;
- }());
-
- var Autolinker = (function () {
-
- function Autolinker(cfg) {
- if (cfg === void 0) { cfg = {}; }
-
- this.version = Autolinker.version;
-
- this.urls = {};
-
- this.email = true;
-
- this.phone = true;
-
- this.hashtag = false;
-
- this.mention = false;
-
- this.newWindow = true;
-
- this.stripPrefix = { scheme: true, www: true };
-
- this.stripTrailingSlash = true;
-
- this.decodePercentEncoding = true;
-
- this.truncate = { length: 0, location: 'end' };
-
- this.className = '';
-
- this.replaceFn = null;
-
- this.context = undefined;
-
- this.matchers = null;
-
- this.tagBuilder = null;
-
-
- this.urls = this.normalizeUrlsCfg(cfg.urls);
- this.email = typeof cfg.email === 'boolean' ? cfg.email : this.email;
- this.phone = typeof cfg.phone === 'boolean' ? cfg.phone : this.phone;
- this.hashtag = cfg.hashtag || this.hashtag;
- this.mention = cfg.mention || this.mention;
- this.newWindow = typeof cfg.newWindow === 'boolean' ? cfg.newWindow : this.newWindow;
- this.stripPrefix = this.normalizeStripPrefixCfg(cfg.stripPrefix);
- this.stripTrailingSlash = typeof cfg.stripTrailingSlash === 'boolean' ? cfg.stripTrailingSlash : this.stripTrailingSlash;
- this.decodePercentEncoding = typeof cfg.decodePercentEncoding === 'boolean' ? cfg.decodePercentEncoding : this.decodePercentEncoding;
-
- var mention = this.mention;
- if (mention !== false && mention !== 'twitter' && mention !== 'instagram' && mention !== 'soundcloud') {
- throw new Error("invalid `mention` cfg - see docs");
- }
-
- var hashtag = this.hashtag;
- if (hashtag !== false && hashtag !== 'twitter' && hashtag !== 'facebook' && hashtag !== 'instagram') {
- throw new Error("invalid `hashtag` cfg - see docs");
- }
- this.truncate = this.normalizeTruncateCfg(cfg.truncate);
- this.className = cfg.className || this.className;
- this.replaceFn = cfg.replaceFn || this.replaceFn;
- this.context = cfg.context || this;
- }
-
- Autolinker.link = function (textOrHtml, options) {
- var autolinker = new Autolinker(options);
- return autolinker.link(textOrHtml);
- };
-
- Autolinker.parse = function (textOrHtml, options) {
- var autolinker = new Autolinker(options);
- return autolinker.parse(textOrHtml);
- };
-
- Autolinker.prototype.normalizeUrlsCfg = function (urls) {
- if (urls == null)
- urls = true;
- if (typeof urls === 'boolean') {
- return { schemeMatches: urls, wwwMatches: urls, tldMatches: urls };
- }
- else {
- return {
- schemeMatches: typeof urls.schemeMatches === 'boolean' ? urls.schemeMatches : true,
- wwwMatches: typeof urls.wwwMatches === 'boolean' ? urls.wwwMatches : true,
- tldMatches: typeof urls.tldMatches === 'boolean' ? urls.tldMatches : true
- };
- }
- };
-
- Autolinker.prototype.normalizeStripPrefixCfg = function (stripPrefix) {
- if (stripPrefix == null)
- stripPrefix = true;
- if (typeof stripPrefix === 'boolean') {
- return { scheme: stripPrefix, www: stripPrefix };
- }
- else {
- return {
- scheme: typeof stripPrefix.scheme === 'boolean' ? stripPrefix.scheme : true,
- www: typeof stripPrefix.www === 'boolean' ? stripPrefix.www : true
- };
- }
- };
-
- Autolinker.prototype.normalizeTruncateCfg = function (truncate) {
- if (typeof truncate === 'number') {
- return { length: truncate, location: 'end' };
- }
- else {
- return defaults(truncate || {}, {
- length: Number.POSITIVE_INFINITY,
- location: 'end'
- });
- }
- };
-
- Autolinker.prototype.parse = function (textOrHtml) {
- var _this = this;
- var skipTagNames = ['a', 'style', 'script'], skipTagsStackCount = 0,
- matches = [];
-
-
- parseHtml(textOrHtml, {
- onOpenTag: function (tagName) {
- if (skipTagNames.indexOf(tagName) >= 0) {
- skipTagsStackCount++;
- }
- },
- onText: function (text, offset) {
-
- if (skipTagsStackCount === 0) {
-
-
-
-
-
- var htmlCharacterEntitiesRegex = /( | |<|<|>|>|"|"|')/gi;
- var textSplit = splitAndCapture(text, htmlCharacterEntitiesRegex);
- var currentOffset_1 = offset;
- textSplit.forEach(function (splitText, i) {
-
- if (i % 2 === 0) {
- var textNodeMatches = _this.parseText(splitText, currentOffset_1);
- matches.push.apply(matches, textNodeMatches);
- }
- currentOffset_1 += splitText.length;
- });
- }
- },
- onCloseTag: function (tagName) {
- if (skipTagNames.indexOf(tagName) >= 0) {
- skipTagsStackCount = Math.max(skipTagsStackCount - 1, 0);
- }
- },
- onComment: function (offset) { },
- onDoctype: function (offset) { },
- });
-
-
-
- matches = this.compactMatches(matches);
-
-
-
-
- matches = this.removeUnwantedMatches(matches);
- return matches;
- };
-
- Autolinker.prototype.compactMatches = function (matches) {
-
- matches.sort(function (a, b) { return a.getOffset() - b.getOffset(); });
- for (var i = 0; i < matches.length - 1; i++) {
- var match = matches[i], offset = match.getOffset(), matchedTextLength = match.getMatchedText().length, endIdx = offset + matchedTextLength;
- if (i + 1 < matches.length) {
-
- if (matches[i + 1].getOffset() === offset) {
- var removeIdx = matches[i + 1].getMatchedText().length > matchedTextLength ? i : i + 1;
- matches.splice(removeIdx, 1);
- continue;
- }
-
- if (matches[i + 1].getOffset() < endIdx) {
- matches.splice(i + 1, 1);
- }
- }
- }
- return matches;
- };
-
- Autolinker.prototype.removeUnwantedMatches = function (matches) {
- if (!this.hashtag)
- remove(matches, function (match) { return match.getType() === 'hashtag'; });
- if (!this.email)
- remove(matches, function (match) { return match.getType() === 'email'; });
- if (!this.phone)
- remove(matches, function (match) { return match.getType() === 'phone'; });
- if (!this.mention)
- remove(matches, function (match) { return match.getType() === 'mention'; });
- if (!this.urls.schemeMatches) {
- remove(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'scheme'; });
- }
- if (!this.urls.wwwMatches) {
- remove(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'www'; });
- }
- if (!this.urls.tldMatches) {
- remove(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'tld'; });
- }
- return matches;
- };
-
- Autolinker.prototype.parseText = function (text, offset) {
- if (offset === void 0) { offset = 0; }
- offset = offset || 0;
- var matchers = this.getMatchers(), matches = [];
- for (var i = 0, numMatchers = matchers.length; i < numMatchers; i++) {
- var textMatches = matchers[i].parseMatches(text);
-
-
-
-
- for (var j = 0, numTextMatches = textMatches.length; j < numTextMatches; j++) {
- textMatches[j].setOffset(offset + textMatches[j].getOffset());
- }
- matches.push.apply(matches, textMatches);
- }
- return matches;
- };
-
- Autolinker.prototype.link = function (textOrHtml) {
- if (!textOrHtml) {
- return "";
- }
- var matches = this.parse(textOrHtml), newHtml = [], lastIndex = 0;
- for (var i = 0, len = matches.length; i < len; i++) {
- var match = matches[i];
- newHtml.push(textOrHtml.substring(lastIndex, match.getOffset()));
- newHtml.push(this.createMatchReturnVal(match));
- lastIndex = match.getOffset() + match.getMatchedText().length;
- }
- newHtml.push(textOrHtml.substring(lastIndex));
- return newHtml.join('');
- };
-
- Autolinker.prototype.createMatchReturnVal = function (match) {
-
- var replaceFnResult;
- if (this.replaceFn) {
- replaceFnResult = this.replaceFn.call(this.context, match);
- }
- if (typeof replaceFnResult === 'string') {
- return replaceFnResult;
- }
- else if (replaceFnResult === false) {
- return match.getMatchedText();
- }
- else if (replaceFnResult instanceof HtmlTag) {
- return replaceFnResult.toAnchorString();
- }
- else {
-
- var anchorTag = match.buildTag();
- return anchorTag.toAnchorString();
- }
- };
-
- Autolinker.prototype.getMatchers = function () {
- if (!this.matchers) {
- var tagBuilder = this.getTagBuilder();
- var matchers = [
- new HashtagMatcher({ tagBuilder: tagBuilder, serviceName: this.hashtag }),
- new EmailMatcher({ tagBuilder: tagBuilder }),
- new PhoneMatcher({ tagBuilder: tagBuilder }),
- new MentionMatcher({ tagBuilder: tagBuilder, serviceName: this.mention }),
- new UrlMatcher({ tagBuilder: tagBuilder, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash, decodePercentEncoding: this.decodePercentEncoding })
- ];
- return (this.matchers = matchers);
- }
- else {
- return this.matchers;
- }
- };
-
- Autolinker.prototype.getTagBuilder = function () {
- var tagBuilder = this.tagBuilder;
- if (!tagBuilder) {
- tagBuilder = this.tagBuilder = new AnchorTagBuilder({
- newWindow: this.newWindow,
- truncate: this.truncate,
- className: this.className
- });
- }
- return tagBuilder;
- };
-
- Autolinker.version = '3.11.0';
-
- Autolinker.AnchorTagBuilder = AnchorTagBuilder;
-
- Autolinker.HtmlTag = HtmlTag;
-
- Autolinker.matcher = {
- Email: EmailMatcher,
- Hashtag: HashtagMatcher,
- Matcher: Matcher,
- Mention: MentionMatcher,
- Phone: PhoneMatcher,
- Url: UrlMatcher
- };
-
- Autolinker.match = {
- Email: EmailMatch,
- Hashtag: HashtagMatch,
- Match: Match,
- Mention: MentionMatch,
- Phone: PhoneMatch,
- Url: UrlMatch
- };
- return Autolinker;
- }());
- return Autolinker;
- }));
- export default tmp.Autolinker;
|