|
;(function () { |
|
'use strict'; |
|
|
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; |
|
|
|
(function (exports) { |
|
'use strict'; |
|
|
|
function inherits(parent, child) { |
|
var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
|
|
|
var extended = Object.create(parent.prototype); |
|
for (var p in props) { |
|
extended[p] = props[p]; |
|
} |
|
extended.constructor = child; |
|
child.prototype = extended; |
|
return child; |
|
} |
|
|
|
var defaults = { |
|
defaultProtocol: 'http', |
|
events: null, |
|
format: noop, |
|
formatHref: noop, |
|
nl2br: false, |
|
tagName: 'a', |
|
target: typeToTarget, |
|
validate: true, |
|
ignoreTags: [], |
|
attributes: null, |
|
className: 'linkified' }; |
|
|
|
function Options(opts) { |
|
opts = opts || {}; |
|
|
|
this.defaultProtocol = opts.defaultProtocol || defaults.defaultProtocol; |
|
this.events = opts.events || defaults.events; |
|
this.format = opts.format || defaults.format; |
|
this.formatHref = opts.formatHref || defaults.formatHref; |
|
this.nl2br = opts.nl2br || defaults.nl2br; |
|
this.tagName = opts.tagName || defaults.tagName; |
|
this.target = opts.target || defaults.target; |
|
this.validate = opts.validate || defaults.validate; |
|
this.ignoreTags = []; |
|
|
|
|
|
this.attributes = opts.attributes || opts.linkAttributes || defaults.attributes; |
|
this.className = opts.className || opts.linkClass || defaults.className; |
|
|
|
|
|
|
|
var ignoredTags = opts.ignoreTags || defaults.ignoreTags; |
|
for (var i = 0; i < ignoredTags.length; i++) { |
|
this.ignoreTags.push(ignoredTags[i].toUpperCase()); |
|
} |
|
} |
|
|
|
Options.prototype = { |
|
|
|
|
|
|
|
resolve: function resolve(token) { |
|
var href = token.toHref(this.defaultProtocol); |
|
return { |
|
formatted: this.get('format', token.toString(), token), |
|
formattedHref: this.get('formatHref', href, token), |
|
tagName: this.get('tagName', href, token), |
|
className: this.get('className', href, token), |
|
target: this.get('target', href, token), |
|
events: this.getObject('events', href, token), |
|
attributes: this.getObject('attributes', href, token) |
|
}; |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
check: function check(token) { |
|
return this.get('validate', token.toString(), token); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get: function get(key, operator, token) { |
|
var option = this[key]; |
|
|
|
if (!option) { |
|
return option; |
|
} |
|
|
|
switch (typeof option === 'undefined' ? 'undefined' : _typeof(option)) { |
|
case 'function': |
|
return option(operator, token.type); |
|
case 'object': |
|
var optionValue = option[token.type] || defaults[key]; |
|
return typeof optionValue === 'function' ? optionValue(operator, token.type) : optionValue; |
|
} |
|
|
|
return option; |
|
}, |
|
getObject: function getObject(key, operator, token) { |
|
var option = this[key]; |
|
return typeof option === 'function' ? option(operator, token.type) : option; |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
function contains(arr, value) { |
|
for (var i = 0; i < arr.length; i++) { |
|
if (arr[i] === value) { |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
function noop(val) { |
|
return val; |
|
} |
|
|
|
function typeToTarget(href, type) { |
|
return type === 'url' ? '_blank' : null; |
|
} |
|
|
|
var options = Object.freeze({ |
|
defaults: defaults, |
|
Options: Options, |
|
contains: contains |
|
}); |
|
|
|
function createStateClass() { |
|
return function (tClass) { |
|
this.j = []; |
|
this.T = tClass || null; |
|
}; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var BaseState = createStateClass(); |
|
BaseState.prototype = { |
|
defaultTransition: false, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
on: function on(symbol, state) { |
|
if (symbol instanceof Array) { |
|
for (var i = 0; i < symbol.length; i++) { |
|
this.j.push([symbol[i], state]); |
|
} |
|
return this; |
|
} |
|
this.j.push([symbol, state]); |
|
return this; |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next: function next(item) { |
|
for (var i = 0; i < this.j.length; i++) { |
|
var jump = this.j[i]; |
|
var symbol = jump[0]; |
|
var state = jump[1]; |
|
|
|
|
|
if (this.test(item, symbol)) { |
|
return state; |
|
} |
|
} |
|
|
|
|
|
return this.defaultTransition; |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
accepts: function accepts() { |
|
return !!this.T; |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test: function test(item, symbol) { |
|
return item === symbol; |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emit: function emit() { |
|
return this.T; |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var CharacterState = inherits(BaseState, createStateClass(), { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test: function test(character, charOrRegExp) { |
|
return character === charOrRegExp || charOrRegExp instanceof RegExp && charOrRegExp.test(character); |
|
} |
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var TokenState = inherits(BaseState, createStateClass(), { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jump: function jump(token) { |
|
var tClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; |
|
|
|
var state = this.next(new token('')); |
|
if (state === this.defaultTransition) { |
|
|
|
state = new this.constructor(tClass); |
|
this.on(token, state); |
|
} else if (tClass) { |
|
state.T = tClass; |
|
} |
|
return state; |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test: function test(token, tokenClass) { |
|
return token instanceof tokenClass; |
|
} |
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function stateify(str, start, endToken, defaultToken) { |
|
var i = 0, |
|
len = str.length, |
|
state = start, |
|
newStates = [], |
|
nextState = void 0; |
|
|
|
|
|
while (i < len && (nextState = state.next(str[i]))) { |
|
state = nextState; |
|
i++; |
|
} |
|
|
|
if (i >= len) { |
|
return []; |
|
} |
|
|
|
while (i < len - 1) { |
|
nextState = new CharacterState(defaultToken); |
|
newStates.push(nextState); |
|
state.on(str[i], nextState); |
|
state = nextState; |
|
i++; |
|
} |
|
|
|
nextState = new CharacterState(endToken); |
|
newStates.push(nextState); |
|
state.on(str[len - 1], nextState); |
|
|
|
return newStates; |
|
} |
|
|
|
function createTokenClass() { |
|
return function (value) { |
|
if (value) { |
|
this.v = value; |
|
} |
|
}; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var TextToken = createTokenClass(); |
|
TextToken.prototype = { |
|
toString: function toString() { |
|
return this.v + ''; |
|
} |
|
}; |
|
|
|
function inheritsToken(value) { |
|
var props = value ? { v: value } : {}; |
|
return inherits(TextToken, createTokenClass(), props); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
var DOMAIN = inheritsToken(); |
|
|
|
|
|
|
|
|
|
|
|
var AT = inheritsToken('@'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var COLON = inheritsToken(':'); |
|
|
|
|
|
|
|
|
|
|
|
var DOT = inheritsToken('.'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var PUNCTUATION = inheritsToken(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
var LOCALHOST = inheritsToken(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
var NL = inheritsToken('\n'); |
|
|
|
|
|
|
|
|
|
|
|
var NUM = inheritsToken(); |
|
|
|
|
|
|
|
|
|
|
|
var PLUS = inheritsToken('+'); |
|
|
|
|
|
|
|
|
|
|
|
var POUND = inheritsToken('#'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var PROTOCOL = inheritsToken(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var MAILTO = inheritsToken('mailto:'); |
|
|
|
|
|
|
|
|
|
|
|
var QUERY = inheritsToken('?'); |
|
|
|
|
|
|
|
|
|
|
|
var SLASH = inheritsToken('/'); |
|
|
|
|
|
|
|
|
|
|
|
var UNDERSCORE = inheritsToken('_'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
var SYM = inheritsToken(); |
|
|
|
|
|
|
|
|
|
|
|
var TLD = inheritsToken(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var WS = inheritsToken(); |
|
|
|
|
|
|
|
|
|
|
|
var OPENBRACE = inheritsToken('{'); |
|
var OPENBRACKET = inheritsToken('['); |
|
var OPENANGLEBRACKET = inheritsToken('<'); |
|
var OPENPAREN = inheritsToken('('); |
|
var CLOSEBRACE = inheritsToken('}'); |
|
var CLOSEBRACKET = inheritsToken(']'); |
|
var CLOSEANGLEBRACKET = inheritsToken('>'); |
|
var CLOSEPAREN = inheritsToken(')'); |
|
|
|
var AMPERSAND = inheritsToken('&'); |
|
|
|
var text = Object.freeze({ |
|
Base: TextToken, |
|
DOMAIN: DOMAIN, |
|
AT: AT, |
|
COLON: COLON, |
|
DOT: DOT, |
|
PUNCTUATION: PUNCTUATION, |
|
LOCALHOST: LOCALHOST, |
|
NL: NL, |
|
NUM: NUM, |
|
PLUS: PLUS, |
|
POUND: POUND, |
|
QUERY: QUERY, |
|
PROTOCOL: PROTOCOL, |
|
MAILTO: MAILTO, |
|
SLASH: SLASH, |
|
UNDERSCORE: UNDERSCORE, |
|
SYM: SYM, |
|
TLD: TLD, |
|
WS: WS, |
|
OPENBRACE: OPENBRACE, |
|
OPENBRACKET: OPENBRACKET, |
|
OPENANGLEBRACKET: OPENANGLEBRACKET, |
|
OPENPAREN: OPENPAREN, |
|
CLOSEBRACE: CLOSEBRACE, |
|
CLOSEBRACKET: CLOSEBRACKET, |
|
CLOSEANGLEBRACKET: CLOSEANGLEBRACKET, |
|
CLOSEPAREN: CLOSEPAREN, |
|
AMPERSAND: AMPERSAND |
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tlds = 'aaa|aarp|abb|abbott|abogado|ac|academy|accenture|accountant|accountants|aco|active|actor|ad|adac|ads|adult|ae|aeg|aero|af|afl|ag|agency|ai|aig|airforce|airtel|al|alibaba|alipay|allfinanz|alsace|am|amica|amsterdam|an|analytics|android|ao|apartments|app|apple|aq|aquarelle|ar|aramco|archi|army|arpa|arte|as|asia|associates|at|attorney|au|auction|audi|audio|author|auto|autos|avianca|aw|ax|axa|az|azure|ba|baidu|band|bank|bar|barcelona|barclaycard|barclays|bargains|bauhaus|bayern|bb|bbc|bbva|bcg|bcn|bd|be|beats|beer|bentley|berlin|best|bet|bf|bg|bh|bharti|bi|bible|bid|bike|bing|bingo|bio|biz|bj|black|blackfriday|bloomberg|blue|bm|bms|bmw|bn|bnl|bnpparibas|bo|boats|boehringer|bom|bond|boo|book|boots|bosch|bostik|bot|boutique|br|bradesco|bridgestone|broadway|broker|brother|brussels|bs|bt|budapest|bugatti|build|builders|business|buy|buzz|bv|bw|by|bz|bzh|ca|cab|cafe|cal|call|camera|camp|cancerresearch|canon|capetown|capital|car|caravan|cards|care|career|careers|cars|cartier|casa|cash|casino|cat|catering|cba|cbn|cc|cd|ceb|center|ceo|cern|cf|cfa|cfd|cg|ch|chanel|channel|chase|chat|cheap|chloe|christmas|chrome|church|ci|cipriani|circle|cisco|citic|city|cityeats|ck|cl|claims|cleaning|click|clinic|clinique|clothing|cloud|club|clubmed|cm|cn|co|coach|codes|coffee|college|cologne|com|commbank|community|company|compare|computer|comsec|condos|construction|consulting|contact|contractors|cooking|cool|coop|corsica|country|coupon|coupons|courses|cr|credit|creditcard|creditunion|cricket|crown|crs|cruises|csc|cu|cuisinella|cv|cw|cx|cy|cymru|cyou|cz|dabur|dad|dance|date|dating|datsun|day|dclk|de|dealer|deals|degree|delivery|dell|deloitte|delta|democrat|dental|dentist|desi|design|dev|diamonds|diet|digital|direct|directory|discount|dj|dk|dm|dnp|do|docs|dog|doha|domains|download|drive|dubai|durban|dvag|dz|earth|eat|ec|edeka|edu|education|ee|eg|email|emerck|energy|engineer|engineering|enterprises|epson|equipment|er|erni|es|esq|estate|et|eu|eurovision|eus|events|everbank|exchange|expert|exposed|express|fage|fail|fairwinds|faith|family|fan|fans|farm|fashion|fast|feedback|ferrero|fi|film|final|finance|financial|firestone|firmdale|fish|fishing|fit|fitness|fj|fk|flickr|flights|florist|flowers|flsmidth|fly|fm|fo|foo|football|ford|forex|forsale|forum|foundation|fox|fr|fresenius|frl|frogans|frontier|fund|furniture|futbol|fyi|ga|gal|gallery|gallup|game|garden|gb|gbiz|gd|gdn|ge|gea|gent|genting|gf|gg|ggee|gh|gi|gift|gifts|gives|giving|gl|glass|gle|global|globo|gm|gmail|gmbh|gmo|gmx|gn|gold|goldpoint|golf|goo|goog|google|gop|got|gov|gp|gq|gr|grainger|graphics|gratis|green|gripe|group|gs|gt|gu|gucci|guge|guide|guitars|guru|gw|gy|hamburg|hangout|haus|hdfcbank|health|healthcare|help|helsinki|here|hermes|hiphop|hitachi|hiv|hk|hm|hn|hockey|holdings|holiday|homedepot|homes|honda|horse|host|hosting|hoteles|hotmail|house|how|hr|hsbc|ht|hu|hyundai|ibm|icbc|ice|icu|id|ie|ifm|iinet|il|im|immo|immobilien|in|industries|infiniti|info|ing|ink|institute|insurance|insure|int|international|investments|io|ipiranga|iq|ir|irish|is|iselect|ist|istanbul|it|itau|iwc|jaguar|java|jcb|je|jetzt|jewelry|jlc|jll|jm|jmp|jo|jobs|joburg|jot|joy|jp|jpmorgan|jprs|juegos|kaufen|kddi|ke|kerryhotels|kerrylogistics|kerryproperties|kfh|kg|kh|ki|kia|kim|kinder|kitchen|kiwi|km|kn|koeln|komatsu|kp|kpn|kr|krd|kred|kuokgroup|kw|ky|kyoto|kz|la|lacaixa|lamborghini|lamer|lancaster|land|landrover|lanxess|lasalle|lat|latrobe|law|lawyer|lb|lc|lds|lease|leclerc|legal|lexus|lgbt|li|liaison|lidl|life|lifeinsurance|lifestyle|lighting|like|limited|limo|lincoln|linde|link|live|living|lixil|lk|loan|loans|local|locus|lol|london|lotte|lotto|love|lr|ls|lt|ltd|ltda|lu|lupin|luxe|luxury|lv|ly|ma|madrid|maif|maison|makeup|man|management|mango|market|marketing|markets|marriott|mba|mc|md|me|med|media|meet|melbourne|meme|memorial|men|menu|meo|mg|mh|miami|microsoft|mil|mini|mk|ml|mm|mma|mn|mo|mobi|mobily|moda|moe|moi|mom|monash|money|montblanc|mormon|mortgage|moscow|motorcycles|mov|movie|movistar|mp|mq|mr|ms|mt|mtn|mtpc|mtr|mu|museum|mutuelle|mv|mw|mx|my|mz|na|nadex|nagoya|name|natura|navy|nc|ne|nec|net|netbank|network|neustar|new|news|nexus|nf|ng|ngo|nhk|ni|nico|nikon|ninja|nissan|nl|no|nokia|norton|nowruz|np|nr|nra|nrw|ntt|nu|nyc|nz|obi|office|okinawa|om|omega|one|ong|onl|online|ooo|oracle|orange|org|organic|origins|osaka|otsuka|ovh|pa|page|pamperedchef|panerai|paris|pars|partners|parts|party|passagens|pe|pet|pf|pg|ph|pharmacy|philips|photo|photography|photos|physio|piaget|pics|pictet|pictures|pid|pin|ping|pink|pizza|pk|pl|place|play|playstation|plumbing|plus|pm|pn|pohl|poker|porn|post|pr|praxi|press|pro|prod|productions|prof|promo|properties|property|protection|ps|pt|pub|pw|pwc|py|qa|qpon|quebec|quest|racing|re|read|realtor|realty|recipes|red|redstone|redumbrella|rehab|reise|reisen|reit|ren|rent|rentals|repair|report|republican|rest|restaurant|review|reviews|rexroth|rich|ricoh|rio|rip|ro|rocher|rocks|rodeo|room|rs|rsvp|ru|ruhr|run|rw|rwe|ryukyu|sa|saarland|safe|safety|sakura|sale|salon|samsung|sandvik|sandvikcoromant|sanofi|sap|sapo|sarl|sas|saxo|sb|sbs|sc|sca|scb|schaeffler|schmidt|scholarships|school|schule|schwarz|science|scor|scot|sd|se|seat|security|seek|select|sener|services|seven|sew|sex|sexy|sfr|sg|sh|sharp|shell|shia|shiksha|shoes|show|shriram|si|singles|site|sj|sk|ski|skin|sky|skype|sl|sm|smile|sn|sncf|so|soccer|social|softbank|software|sohu|solar|solutions|song|sony|soy|space|spiegel|spot|spreadbetting|sr|srl|st|stada|star|starhub|statefarm|statoil|stc|stcgroup|stockholm|storage|store|studio|study|style|su|sucks|supplies|supply|support|surf|surgery|suzuki|sv|swatch|swiss|sx|sy|sydney|symantec|systems|sz|tab|taipei|taobao|tatamotors|tatar|tattoo|tax|taxi|tc|tci|td|team|tech|technology|tel|telecity|telefonica|temasek|tennis|tf|tg|th|thd|theater|theatre|tickets|tienda|tiffany|tips|tires|tirol|tj|tk|tl|tm|tmall|tn|to|today|tokyo|tools|top|toray|toshiba|total|tours|town|toyota|toys|tp|tr|trade|trading|training|travel|travelers|travelersinsurance|trust|trv|tt|tube|tui|tunes|tushu|tv|tvs|tw|tz|ua|ubs|ug|uk|unicom|university|uno|uol|us|uy|uz|va|vacations|vana|vc|ve|vegas|ventures|verisign|versicherung|vet|vg|vi|viajes|video|viking|villas|vin|vip|virgin|vision|vista|vistaprint|viva|vlaanderen|vn|vodka|volkswagen|vote|voting|voto|voyage|vu|vuelos|wales|walter|wang|wanggou|watch|watches|weather|weatherchannel|webcam|weber|website|wed|wedding|weir|wf|whoswho|wien|wiki|williamhill|win|windows|wine|wme|wolterskluwer|work|works|world|ws|wtc|wtf|xbox|xerox|xin|xperia|xxx|xyz|yachts|yahoo|yamaxun|yandex|ye|yodobashi|yoga|yokohama|youtube|yt|za|zara|zero|zip|zm|zone|zuerich|zw'.split('|'); |
|
|
|
var NUMBERS = '0123456789'.split(''); |
|
var ALPHANUM = '0123456789abcdefghijklmnopqrstuvwxyz'.split(''); |
|
var WHITESPACE = [' ', '\f', '\r', '\t', '\v', '\xA0', '\u1680', '\u180E']; |
|
|
|
var domainStates = []; |
|
var makeState = function makeState(tokenClass) { |
|
return new CharacterState(tokenClass); |
|
}; |
|
|
|
|
|
var S_START = makeState(); |
|
var S_NUM = makeState(NUM); |
|
var S_DOMAIN = makeState(DOMAIN); |
|
var S_DOMAIN_HYPHEN = makeState(); |
|
var S_WS = makeState(WS); |
|
|
|
|
|
S_START.on('@', makeState(AT)).on('.', makeState(DOT)).on('+', makeState(PLUS)).on('#', makeState(POUND)).on('?', makeState(QUERY)).on('/', makeState(SLASH)).on('_', makeState(UNDERSCORE)).on(':', makeState(COLON)).on('{', makeState(OPENBRACE)).on('[', makeState(OPENBRACKET)).on('<', makeState(OPENANGLEBRACKET)).on('(', makeState(OPENPAREN)).on('}', makeState(CLOSEBRACE)).on(']', makeState(CLOSEBRACKET)).on('>', makeState(CLOSEANGLEBRACKET)).on(')', makeState(CLOSEPAREN)).on('&', makeState(AMPERSAND)).on([',', ';', '!', '"', '\''], makeState(PUNCTUATION)); |
|
|
|
|
|
|
|
S_START.on('\n', makeState(NL)).on(WHITESPACE, S_WS); |
|
|
|
|
|
S_WS.on(WHITESPACE, S_WS); |
|
|
|
|
|
|
|
for (var i = 0; i < tlds.length; i++) { |
|
var newStates = stateify(tlds[i], S_START, TLD, DOMAIN); |
|
domainStates.push.apply(domainStates, newStates); |
|
} |
|
|
|
|
|
var partialProtocolFileStates = stateify('file', S_START, DOMAIN, DOMAIN); |
|
var partialProtocolFtpStates = stateify('ftp', S_START, DOMAIN, DOMAIN); |
|
var partialProtocolHttpStates = stateify('http', S_START, DOMAIN, DOMAIN); |
|
var partialProtocolMailtoStates = stateify('mailto', S_START, DOMAIN, DOMAIN); |
|
|
|
|
|
domainStates.push.apply(domainStates, partialProtocolFileStates); |
|
domainStates.push.apply(domainStates, partialProtocolFtpStates); |
|
domainStates.push.apply(domainStates, partialProtocolHttpStates); |
|
|
|
|
|
var S_PROTOCOL_FILE = partialProtocolFileStates.pop(); |
|
var S_PROTOCOL_FTP = partialProtocolFtpStates.pop(); |
|
var S_PROTOCOL_HTTP = partialProtocolHttpStates.pop(); |
|
var S_MAILTO = partialProtocolMailtoStates.pop(); |
|
var S_PROTOCOL_SECURE = makeState(DOMAIN); |
|
var S_FULL_PROTOCOL = makeState(PROTOCOL); |
|
var S_FULL_MAILTO = makeState(MAILTO); |
|
|
|
|
|
S_PROTOCOL_FTP.on('s', S_PROTOCOL_SECURE).on(':', S_FULL_PROTOCOL); |
|
|
|
S_PROTOCOL_HTTP.on('s', S_PROTOCOL_SECURE).on(':', S_FULL_PROTOCOL); |
|
|
|
domainStates.push(S_PROTOCOL_SECURE); |
|
|
|
|
|
S_PROTOCOL_FILE.on(':', S_FULL_PROTOCOL); |
|
S_PROTOCOL_SECURE.on(':', S_FULL_PROTOCOL); |
|
S_MAILTO.on(':', S_FULL_MAILTO); |
|
|
|
|
|
var partialLocalhostStates = stateify('localhost', S_START, LOCALHOST, DOMAIN); |
|
domainStates.push.apply(domainStates, partialLocalhostStates); |
|
|
|
|
|
|
|
|
|
S_START.on(NUMBERS, S_NUM); |
|
S_NUM.on('-', S_DOMAIN_HYPHEN).on(NUMBERS, S_NUM).on(ALPHANUM, S_DOMAIN); |
|
|
|
S_DOMAIN.on('-', S_DOMAIN_HYPHEN).on(ALPHANUM, S_DOMAIN); |
|
|
|
|
|
for (var _i = 0; _i < domainStates.length; _i++) { |
|
domainStates[_i].on('-', S_DOMAIN_HYPHEN).on(ALPHANUM, S_DOMAIN); |
|
} |
|
|
|
S_DOMAIN_HYPHEN.on('-', S_DOMAIN_HYPHEN).on(NUMBERS, S_DOMAIN).on(ALPHANUM, S_DOMAIN); |
|
|
|
|
|
S_START.defaultTransition = makeState(SYM); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var run = function run(str) { |
|
|
|
|
|
|
|
|
|
|
|
var lowerStr = str.replace(/[A-Z]/g, function (c) { |
|
return c.toLowerCase(); |
|
}); |
|
var len = str.length; |
|
var tokens = []; |
|
|
|
var cursor = 0; |
|
|
|
|
|
while (cursor < len) { |
|
var state = S_START; |
|
var secondState = null; |
|
var nextState = null; |
|
var tokenLength = 0; |
|
var latestAccepting = null; |
|
var sinceAccepts = -1; |
|
|
|
while (cursor < len && (nextState = state.next(lowerStr[cursor]))) { |
|
secondState = null; |
|
state = nextState; |
|
|
|
|
|
if (state.accepts()) { |
|
sinceAccepts = 0; |
|
latestAccepting = state; |
|
} else if (sinceAccepts >= 0) { |
|
sinceAccepts++; |
|
} |
|
|
|
tokenLength++; |
|
cursor++; |
|
} |
|
|
|
if (sinceAccepts < 0) { |
|
continue; |
|
} |
|
|
|
|
|
cursor -= sinceAccepts; |
|
tokenLength -= sinceAccepts; |
|
|
|
|
|
var TOKEN = latestAccepting.emit(); |
|
|
|
|
|
tokens.push(new TOKEN(str.substr(cursor - tokenLength, tokenLength))); |
|
} |
|
|
|
return tokens; |
|
}; |
|
|
|
var start = S_START; |
|
|
|
var scanner = Object.freeze({ |
|
State: CharacterState, |
|
TOKENS: text, |
|
run: run, |
|
start: start |
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isDomainToken(token) { |
|
return token instanceof DOMAIN || token instanceof TLD; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var MultiToken = createTokenClass(); |
|
|
|
MultiToken.prototype = { |
|
|
|
|
|
|
|
|
|
|
|
type: 'token', |
|
|
|
|
|
|
|
|
|
|
|
|
|
isLink: false, |
|
|
|
|
|
|
|
|
|
|
|
|
|
toString: function toString() { |
|
var result = []; |
|
for (var _i2 = 0; _i2 < this.v.length; _i2++) { |
|
result.push(this.v[_i2].toString()); |
|
} |
|
return result.join(''); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toHref: function toHref() { |
|
return this.toString(); |
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toObject: function toObject() { |
|
var protocol = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'http'; |
|
|
|
return { |
|
type: this.type, |
|
value: this.toString(), |
|
href: this.toHref(protocol) |
|
}; |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
var MAILTOEMAIL = inherits(MultiToken, createTokenClass(), { |
|
type: 'email', |
|
isLink: true |
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
var EMAIL = inherits(MultiToken, createTokenClass(), { |
|
type: 'email', |
|
isLink: true, |
|
toHref: function toHref() { |
|
var tokens = this.v; |
|
return 'mailto:' + this.toString(); |
|
} |
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
var TEXT = inherits(MultiToken, createTokenClass(), { type: 'text' }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
var NL$1 = inherits(MultiToken, createTokenClass(), { type: 'nl' }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
var URL = inherits(MultiToken, createTokenClass(), { |
|
type: 'url', |
|
isLink: true, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toHref: function toHref() { |
|
var protocol = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'http'; |
|
|
|
var hasProtocol = false; |
|
var hasSlashSlash = false; |
|
var tokens = this.v; |
|
var result = []; |
|
var i = 0; |
|
|
|
|
|
|
|
while (tokens[i] instanceof PROTOCOL) { |
|
hasProtocol = true; |
|
result.push(tokens[i].toString().toLowerCase()); |
|
i++; |
|
} |
|
|
|
|
|
while (tokens[i] instanceof SLASH) { |
|
hasSlashSlash = true; |
|
result.push(tokens[i].toString()); |
|
i++; |
|
} |
|
|
|
|
|
while (isDomainToken(tokens[i])) { |
|
result.push(tokens[i].toString().toLowerCase()); |
|
i++; |
|
} |
|
|
|
|
|
for (; i < tokens.length; i++) { |
|
result.push(tokens[i].toString()); |
|
} |
|
|
|
result = result.join(''); |
|
|
|
if (!(hasProtocol || hasSlashSlash)) { |
|
result = protocol + '://' + result; |
|
} |
|
|
|
return result; |
|
}, |
|
hasProtocol: function hasProtocol() { |
|
return this.v[0] instanceof PROTOCOL; |
|
} |
|
}); |
|
|
|
var multi = Object.freeze({ |
|
Base: MultiToken, |
|
MAILTOEMAIL: MAILTOEMAIL, |
|
EMAIL: EMAIL, |
|
NL: NL$1, |
|
TEXT: TEXT, |
|
URL: URL |
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var makeState$1 = function makeState$1(tokenClass) { |
|
return new TokenState(tokenClass); |
|
}; |
|
|
|
|
|
var S_START$1 = makeState$1(); |
|
|
|
|
|
|
|
var S_PROTOCOL = makeState$1(); |
|
var S_MAILTO$1 = makeState$1(); |
|
var S_PROTOCOL_SLASH = makeState$1(); |
|
var S_PROTOCOL_SLASH_SLASH = makeState$1(); |
|
var S_DOMAIN$1 = makeState$1(); |
|
var S_DOMAIN_DOT = makeState$1(); |
|
var S_TLD = makeState$1(URL); |
|
var S_TLD_COLON = makeState$1(); |
|
var S_TLD_PORT = makeState$1(URL); |
|
var S_URL = makeState$1(URL); |
|
var S_URL_NON_ACCEPTING = makeState$1(); |
|
var S_URL_OPENBRACE = makeState$1(); |
|
var S_URL_OPENBRACKET = makeState$1(); |
|
var S_URL_OPENANGLEBRACKET = makeState$1(); |
|
var S_URL_OPENPAREN = makeState$1(); |
|
var S_URL_OPENBRACE_Q = makeState$1(URL); |
|
var S_URL_OPENBRACKET_Q = makeState$1(URL); |
|
var S_URL_OPENANGLEBRACKET_Q = makeState$1(URL); |
|
var S_URL_OPENPAREN_Q = makeState$1(URL); |
|
var S_URL_OPENBRACE_SYMS = makeState$1(); |
|
var S_URL_OPENBRACKET_SYMS = makeState$1(); |
|
var S_URL_OPENANGLEBRACKET_SYMS = makeState$1(); |
|
var S_URL_OPENPAREN_SYMS = makeState$1(); |
|
var S_EMAIL_DOMAIN = makeState$1(); |
|
var S_EMAIL_DOMAIN_DOT = makeState$1(); |
|
var S_EMAIL = makeState$1(EMAIL); |
|
var S_EMAIL_COLON = makeState$1(); |
|
var S_EMAIL_PORT = makeState$1(EMAIL); |
|
var S_MAILTO_EMAIL = makeState$1(MAILTOEMAIL); |
|
var S_MAILTO_EMAIL_NON_ACCEPTING = makeState$1(); |
|
var S_LOCALPART = makeState$1(); |
|
var S_LOCALPART_AT = makeState$1(); |
|
var S_LOCALPART_DOT = makeState$1(); |
|
var S_NL = makeState$1(NL$1); |
|
|
|
|
|
S_START$1.on(NL, S_NL).on(PROTOCOL, S_PROTOCOL).on(MAILTO, S_MAILTO$1).on(SLASH, S_PROTOCOL_SLASH); |
|
|
|
S_PROTOCOL.on(SLASH, S_PROTOCOL_SLASH); |
|
S_PROTOCOL_SLASH.on(SLASH, S_PROTOCOL_SLASH_SLASH); |
|
|
|
|
|
S_START$1.on(TLD, S_DOMAIN$1).on(DOMAIN, S_DOMAIN$1).on(LOCALHOST, S_TLD).on(NUM, S_DOMAIN$1); |
|
|
|
|
|
S_PROTOCOL_SLASH_SLASH.on(TLD, S_URL).on(DOMAIN, S_URL).on(NUM, S_URL).on(LOCALHOST, S_URL); |
|
|
|
|
|
|
|
S_DOMAIN$1.on(DOT, S_DOMAIN_DOT); |
|
S_EMAIL_DOMAIN.on(DOT, S_EMAIL_DOMAIN_DOT); |
|
|
|
|
|
|
|
|
|
S_DOMAIN_DOT.on(TLD, S_TLD).on(DOMAIN, S_DOMAIN$1).on(NUM, S_DOMAIN$1).on(LOCALHOST, S_DOMAIN$1); |
|
|
|
S_EMAIL_DOMAIN_DOT.on(TLD, S_EMAIL).on(DOMAIN, S_EMAIL_DOMAIN).on(NUM, S_EMAIL_DOMAIN).on(LOCALHOST, S_EMAIL_DOMAIN); |
|
|
|
|
|
|
|
S_TLD.on(DOT, S_DOMAIN_DOT); |
|
S_EMAIL.on(DOT, S_EMAIL_DOMAIN_DOT); |
|
|
|
|
|
|
|
S_TLD.on(COLON, S_TLD_COLON).on(SLASH, S_URL); |
|
S_TLD_COLON.on(NUM, S_TLD_PORT); |
|
S_TLD_PORT.on(SLASH, S_URL); |
|
S_EMAIL.on(COLON, S_EMAIL_COLON); |
|
S_EMAIL_COLON.on(NUM, S_EMAIL_PORT); |
|
|
|
|
|
var qsAccepting = [DOMAIN, AT, LOCALHOST, NUM, PLUS, POUND, PROTOCOL, SLASH, TLD, UNDERSCORE, SYM, AMPERSAND]; |
|
|
|
|
|
|
|
|
|
var qsNonAccepting = [COLON, DOT, QUERY, PUNCTUATION, CLOSEBRACE, CLOSEBRACKET, CLOSEANGLEBRACKET, CLOSEPAREN, OPENBRACE, OPENBRACKET, OPENANGLEBRACKET, OPENPAREN]; |
|
|
|
|
|
|
|
|
|
|
|
S_URL.on(OPENBRACE, S_URL_OPENBRACE).on(OPENBRACKET, S_URL_OPENBRACKET).on(OPENANGLEBRACKET, S_URL_OPENANGLEBRACKET).on(OPENPAREN, S_URL_OPENPAREN); |
|
|
|
|
|
S_URL_NON_ACCEPTING.on(OPENBRACE, S_URL_OPENBRACE).on(OPENBRACKET, S_URL_OPENBRACKET).on(OPENANGLEBRACKET, S_URL_OPENANGLEBRACKET).on(OPENPAREN, S_URL_OPENPAREN); |
|
|
|
|
|
S_URL_OPENBRACE.on(CLOSEBRACE, S_URL); |
|
S_URL_OPENBRACKET.on(CLOSEBRACKET, S_URL); |
|
S_URL_OPENANGLEBRACKET.on(CLOSEANGLEBRACKET, S_URL); |
|
S_URL_OPENPAREN.on(CLOSEPAREN, S_URL); |
|
S_URL_OPENBRACE_Q.on(CLOSEBRACE, S_URL); |
|
S_URL_OPENBRACKET_Q.on(CLOSEBRACKET, S_URL); |
|
S_URL_OPENANGLEBRACKET_Q.on(CLOSEANGLEBRACKET, S_URL); |
|
S_URL_OPENPAREN_Q.on(CLOSEPAREN, S_URL); |
|
S_URL_OPENBRACE_SYMS.on(CLOSEBRACE, S_URL); |
|
S_URL_OPENBRACKET_SYMS.on(CLOSEBRACKET, S_URL); |
|
S_URL_OPENANGLEBRACKET_SYMS.on(CLOSEANGLEBRACKET, S_URL); |
|
S_URL_OPENPAREN_SYMS.on(CLOSEPAREN, S_URL); |
|
|
|
|
|
|
|
|
|
S_URL_OPENBRACE.on(qsAccepting, S_URL_OPENBRACE_Q); |
|
S_URL_OPENBRACKET.on(qsAccepting, S_URL_OPENBRACKET_Q); |
|
S_URL_OPENANGLEBRACKET.on(qsAccepting, S_URL_OPENANGLEBRACKET_Q); |
|
S_URL_OPENPAREN.on(qsAccepting, S_URL_OPENPAREN_Q); |
|
S_URL_OPENBRACE.on(qsNonAccepting, S_URL_OPENBRACE_SYMS); |
|
S_URL_OPENBRACKET.on(qsNonAccepting, S_URL_OPENBRACKET_SYMS); |
|
S_URL_OPENANGLEBRACKET.on(qsNonAccepting, S_URL_OPENANGLEBRACKET_SYMS); |
|
S_URL_OPENPAREN.on(qsNonAccepting, S_URL_OPENPAREN_SYMS); |
|
|
|
|
|
S_URL_OPENBRACE_Q.on(qsAccepting, S_URL_OPENBRACE_Q); |
|
S_URL_OPENBRACKET_Q.on(qsAccepting, S_URL_OPENBRACKET_Q); |
|
S_URL_OPENANGLEBRACKET_Q.on(qsAccepting, S_URL_OPENANGLEBRACKET_Q); |
|
S_URL_OPENPAREN_Q.on(qsAccepting, S_URL_OPENPAREN_Q); |
|
S_URL_OPENBRACE_Q.on(qsNonAccepting, S_URL_OPENBRACE_Q); |
|
S_URL_OPENBRACKET_Q.on(qsNonAccepting, S_URL_OPENBRACKET_Q); |
|
S_URL_OPENANGLEBRACKET_Q.on(qsNonAccepting, S_URL_OPENANGLEBRACKET_Q); |
|
S_URL_OPENPAREN_Q.on(qsNonAccepting, S_URL_OPENPAREN_Q); |
|
|
|
S_URL_OPENBRACE_SYMS.on(qsAccepting, S_URL_OPENBRACE_Q); |
|
S_URL_OPENBRACKET_SYMS.on(qsAccepting, S_URL_OPENBRACKET_Q); |
|
S_URL_OPENANGLEBRACKET_SYMS.on(qsAccepting, S_URL_OPENANGLEBRACKET_Q); |
|
S_URL_OPENPAREN_SYMS.on(qsAccepting, S_URL_OPENPAREN_Q); |
|
S_URL_OPENBRACE_SYMS.on(qsNonAccepting, S_URL_OPENBRACE_SYMS); |
|
S_URL_OPENBRACKET_SYMS.on(qsNonAccepting, S_URL_OPENBRACKET_SYMS); |
|
S_URL_OPENANGLEBRACKET_SYMS.on(qsNonAccepting, S_URL_OPENANGLEBRACKET_SYMS); |
|
S_URL_OPENPAREN_SYMS.on(qsNonAccepting, S_URL_OPENPAREN_SYMS); |
|
|
|
|
|
S_URL.on(qsAccepting, S_URL); |
|
S_URL_NON_ACCEPTING.on(qsAccepting, S_URL); |
|
|
|
S_URL.on(qsNonAccepting, S_URL_NON_ACCEPTING); |
|
S_URL_NON_ACCEPTING.on(qsNonAccepting, S_URL_NON_ACCEPTING); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
S_MAILTO$1.on(TLD, S_MAILTO_EMAIL).on(DOMAIN, S_MAILTO_EMAIL).on(NUM, S_MAILTO_EMAIL).on(LOCALHOST, S_MAILTO_EMAIL); |
|
|
|
|
|
S_MAILTO_EMAIL.on(qsAccepting, S_MAILTO_EMAIL).on(qsNonAccepting, S_MAILTO_EMAIL_NON_ACCEPTING); |
|
S_MAILTO_EMAIL_NON_ACCEPTING.on(qsAccepting, S_MAILTO_EMAIL).on(qsNonAccepting, S_MAILTO_EMAIL_NON_ACCEPTING); |
|
|
|
|
|
|
|
var localpartAccepting = [DOMAIN, NUM, PLUS, POUND, QUERY, UNDERSCORE, SYM, AMPERSAND, TLD]; |
|
|
|
|
|
|
|
S_DOMAIN$1.on(localpartAccepting, S_LOCALPART).on(AT, S_LOCALPART_AT); |
|
S_TLD.on(localpartAccepting, S_LOCALPART).on(AT, S_LOCALPART_AT); |
|
S_DOMAIN_DOT.on(localpartAccepting, S_LOCALPART); |
|
|
|
|
|
|
|
S_LOCALPART.on(localpartAccepting, S_LOCALPART).on(AT, S_LOCALPART_AT) |
|
.on(DOT, S_LOCALPART_DOT); |
|
S_LOCALPART_DOT.on(localpartAccepting, S_LOCALPART); |
|
S_LOCALPART_AT.on(TLD, S_EMAIL_DOMAIN).on(DOMAIN, S_EMAIL_DOMAIN).on(LOCALHOST, S_EMAIL); |
|
|
|
|
|
var run$1 = function run$1(tokens) { |
|
var len = tokens.length; |
|
var cursor = 0; |
|
var multis = []; |
|
var textTokens = []; |
|
|
|
while (cursor < len) { |
|
var state = S_START$1; |
|
var secondState = null; |
|
var nextState = null; |
|
var multiLength = 0; |
|
var latestAccepting = null; |
|
var sinceAccepts = -1; |
|
|
|
while (cursor < len && !(secondState = state.next(tokens[cursor]))) { |
|
|
|
|
|
textTokens.push(tokens[cursor++]); |
|
} |
|
|
|
while (cursor < len && (nextState = secondState || state.next(tokens[cursor]))) { |
|
|
|
|
|
secondState = null; |
|
state = nextState; |
|
|
|
|
|
if (state.accepts()) { |
|
sinceAccepts = 0; |
|
latestAccepting = state; |
|
} else if (sinceAccepts >= 0) { |
|
sinceAccepts++; |
|
} |
|
|
|
cursor++; |
|
multiLength++; |
|
} |
|
|
|
if (sinceAccepts < 0) { |
|
|
|
|
|
|
|
for (var _i3 = cursor - multiLength; _i3 < cursor; _i3++) { |
|
textTokens.push(tokens[_i3]); |
|
} |
|
} else { |
|
|
|
|
|
|
|
|
|
if (textTokens.length > 0) { |
|
multis.push(new TEXT(textTokens)); |
|
textTokens = []; |
|
} |
|
|
|
|
|
cursor -= sinceAccepts; |
|
multiLength -= sinceAccepts; |
|
|
|
|
|
var MULTI = latestAccepting.emit(); |
|
multis.push(new MULTI(tokens.slice(cursor - multiLength, cursor))); |
|
} |
|
} |
|
|
|
|
|
if (textTokens.length > 0) { |
|
multis.push(new TEXT(textTokens)); |
|
} |
|
|
|
return multis; |
|
}; |
|
|
|
var parser = Object.freeze({ |
|
State: TokenState, |
|
TOKENS: multi, |
|
run: run$1, |
|
start: S_START$1 |
|
}); |
|
|
|
if (!Array.isArray) { |
|
Array.isArray = function (arg) { |
|
return Object.prototype.toString.call(arg) === '[object Array]'; |
|
}; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tokenize = function tokenize(str) { |
|
return run$1(run(str)); |
|
}; |
|
|
|
|
|
|
|
|
|
var find = function find(str) { |
|
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; |
|
|
|
var tokens = tokenize(str); |
|
var filtered = []; |
|
|
|
for (var i = 0; i < tokens.length; i++) { |
|
var token = tokens[i]; |
|
if (token.isLink && (!type || token.type === type)) { |
|
filtered.push(token.toObject()); |
|
} |
|
} |
|
|
|
return filtered; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var test = function test(str) { |
|
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; |
|
|
|
var tokens = tokenize(str); |
|
return tokens.length === 1 && tokens[0].isLink && (!type || tokens[0].type === type); |
|
}; |
|
|
|
exports.find = find; |
|
exports.inherits = inherits; |
|
exports.options = options; |
|
exports.parser = parser; |
|
exports.scanner = scanner; |
|
exports.test = test; |
|
exports.tokenize = tokenize; |
|
})(self.linkify = self.linkify || {}); |
|
})(); |