1/*! 2 * Autolinker.js 3 * 3.14.3 4 * 5 * Copyright(c) 2021 Gregory Jacobs <[email protected]> 6 * MIT License 7 * 8 * https://github.com/gregjacobs/Autolinker.js 9 */ 10(function (global, factory) { 11 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 12 typeof define === 'function' && define.amd ? define(factory) : 13 (global = global || self, global.Autolinker = factory()); 14}(this, function () { 'use strict'; 15 16 /** 17 * Assigns (shallow copies) the properties of `src` onto `dest`, if the 18 * corresponding property on `dest` === `undefined`. 19 * 20 * @param {Object} dest The destination object. 21 * @param {Object} src The source object. 22 * @return {Object} The destination object (`dest`) 23 */ 24 function defaults(dest, src) { 25 for (var prop in src) { 26 if (src.hasOwnProperty(prop) && dest[prop] === undefined) { 27 dest[prop] = src[prop]; 28 } 29 } 30 return dest; 31 } 32 /** 33 * Truncates the `str` at `len - ellipsisChars.length`, and adds the `ellipsisChars` to the 34 * end of the string (by default, two periods: '..'). If the `str` length does not exceed 35 * `len`, the string will be returned unchanged. 36 * 37 * @param {String} str The string to truncate and add an ellipsis to. 38 * @param {Number} truncateLen The length to truncate the string at. 39 * @param {String} [ellipsisChars=...] The ellipsis character(s) to add to the end of `str` 40 * when truncated. Defaults to '...' 41 */ 42 function ellipsis(str, truncateLen, ellipsisChars) { 43 var ellipsisLength; 44 if (str.length > truncateLen) { 45 if (ellipsisChars == null) { 46 ellipsisChars = '…'; 47 ellipsisLength = 3; 48 } 49 else { 50 ellipsisLength = ellipsisChars.length; 51 } 52 str = str.substring(0, truncateLen - ellipsisLength) + ellipsisChars; 53 } 54 return str; 55 } 56 /** 57 * Supports `Array.prototype.indexOf()` functionality for old IE (IE8 and below). 58 * 59 * @param {Array} arr The array to find an element of. 60 * @param {*} element The element to find in the array, and return the index of. 61 * @return {Number} The index of the `element`, or -1 if it was not found. 62 */ 63 function indexOf(arr, element) { 64 // @ts-ignore - As far as TypeScript is concerned, this method will always 65 // exist (lowest "lib" in TS is "ES5"). Hence we need to ignore this error 66 // to support IE8 which only implements ES3 and doesn't have this method 67 if (Array.prototype.indexOf) { 68 return arr.indexOf(element); 69 } 70 else { 71 for (var i = 0, len = arr.length; i < len; i++) { 72 if (arr[i] === element) 73 return i; 74 } 75 return -1; 76 } 77 } 78 /** 79 * Removes array elements based on a filtering function. Mutates the input 80 * array. 81 * 82 * Using this instead of the ES5 Array.prototype.filter() function, to allow 83 * Autolinker compatibility with IE8, and also to prevent creating many new 84 * arrays in memory for filtering. 85 * 86 * @param {Array} arr The array to remove elements from. This array is 87 * mutated. 88 * @param {Function} fn A function which should return `true` to 89 * remove an element. 90 * @return {Array} The mutated input `arr`. 91 */ 92 function remove(arr, fn) { 93 for (var i = arr.length - 1; i >= 0; i--) { 94 if (fn(arr[i]) === true) { 95 arr.splice(i, 1); 96 } 97 } 98 } 99 /** 100 * Performs the functionality of what modern browsers do when `String.prototype.split()` is called 101 * with a regular expression that contains capturing parenthesis. 102 * 103 * For example: 104 * 105 * // Modern browsers: 106 * "a,b,c".split( /(,)/ ); // --> [ 'a', ',', 'b', ',', 'c' ] 107 * 108 * // Old IE (including IE8): 109 * "a,b,c".split( /(,)/ ); // --> [ 'a', 'b', 'c' ] 110 * 111 * This method emulates the functionality of modern browsers for the old IE case. 112 * 113 * @param {String} str The string to split. 114 * @param {RegExp} splitRegex The regular expression to split the input `str` on. The splitting 115 * character(s) will be spliced into the array, as in the "modern browsers" example in the 116 * description of this method. 117 * Note #1: the supplied regular expression **must** have the 'g' flag specified. 118 * Note #2: for simplicity's sake, the regular expression does not need 119 * to contain capturing parenthesis - it will be assumed that any match has them. 120 * @return {String[]}
120 The split array of strings, with the splitting character(s) included. 121 */ 122 function splitAndCapture(str, splitRegex) { 123 if (!splitRegex.global) 124 throw new Error("`splitRegex` must have the 'g' flag set"); 125 var result = [], lastIdx = 0, match; 126 while (match = splitRegex.exec(str)) { 127 result.push(str.substring(lastIdx, match.index)); 128 result.push(match[0]); // push the splitting char(s) 129 lastIdx = match.index + match[0].length; 130 } 131 result.push(str.substring(lastIdx)); 132 return result; 133 } 134 /** 135 * Function that should never be called but is used to check that every 136 * enum value is handled using TypeScript's 'never' type. 137 */ 138 function throwUnhandledCaseError(theValue) { 139 throw new Error("Unhandled case for value: '" + theValue + "'"); 140 } 141 142 /** 143 * @class Autolinker.HtmlTag 144 * @extends Object 145 * 146 * Represents an HTML tag, which can be used to easily build/modify HTML tags programmatically. 147 * 148 * Autolinker uses this abstraction to create HTML tags, and then write them out as strings. You may also use 149 * this class in your code, especially within a {@link Autolinker#replaceFn replaceFn}. 150 * 151 * ## Examples 152 * 153 * Example instantiation: 154 * 155 * var tag = new Autolinker.HtmlTag( { 156 * tagName : 'a', 157 * attrs : { 'href': 'http://google.com', 'class': 'external-link' }, 158 * innerHtml : 'Google' 159 * } ); 160 * 161 * tag.toAnchorString(); // <a href="http://google.com" class="external-link">Google</a> 162 * 163 * // Individual accessor methods 164 * tag.getTagName(); // 'a' 165 * tag.getAttr( 'href' ); // 'http://google.com' 166 * tag.hasClass( 'external-link' ); // true 167 * 168 * 169 * Using mutator methods (which may be used in combination with instantiation config properties): 170 * 171 * var tag = new Autolinker.HtmlTag(); 172 * tag.setTagName( 'a' ); 173 * tag.setAttr( 'href', 'http://google.com' ); 174 * tag.addClass( 'external-link' ); 175 * tag.setInnerHtml( 'Google' ); 176 * 177 * tag.getTagName(); // 'a' 178 * tag.getAttr( 'href' ); // 'http://google.com' 179 * tag.hasClass( 'external-link' ); // true 180 * 181 * tag.toAnchorString(); // <a href="http://google.com" class="external-link">Google</a> 182 * 183 * 184 * ## Example use within a {@link Autolinker#replaceFn replaceFn} 185 * 186 * var html = Autolinker.link( "Test google.com", { 187 * replaceFn : function( match ) { 188 * var tag = match.buildTag(); // returns an {@link Autolinker.HtmlTag} instance, configured with the Match's href and anchor text 189 * tag.setAttr( 'rel', 'nofollow' ); 190 * 191 * return tag; 192 * } 193 * } ); 194 * 195 * // generated html: 196 * // Test <a href="http://google.com" target="_blank" rel="nofollow">google.com</a> 197 * 198 * 199 * ## Example use with a new tag for the replacement 200 * 201 * var html = Autolinker.link( "Test google.com", { 202 * replaceFn : function( match ) { 203 * var tag = new Autolinker.HtmlTag( { 204 * tagName : 'button',
vendor: 7,965 bytes, lines 205-383
205 * attrs : { 'title': 'Load URL: ' + match.getAnchorHref() }, 206 * innerHtml : 'Load URL: ' + match.getAnchorText() 207 * } ); 208 * 209 * return tag; 210 * } 211 * } ); 212 * 213 * // generated html: 214 * // Test <button title="Load URL: http://google.com">Load URL: google.com</button> 215 */ 216 var HtmlTag = /** @class */ (function () { 217 /** 218 * @method constructor 219 * @param {Object} [cfg] The configuration properties for this class, in an Object (map) 220 */ 221 function HtmlTag(cfg) { 222 if (cfg === void 0) { cfg = {}; } 223 /** 224 * @cfg {String} tagName 225 * 226 * The tag name. Ex: 'a', 'button', etc. 227 * 228 * Not required at instantiation time, but should be set using {@link #setTagName} before {@link #toAnchorString} 229 * is executed. 230 */ 231 this.tagName = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 232 /** 233 * @cfg {Object.<String, String>} attrs 234 * 235 * An key/value Object (map) of attributes to create the tag with. The keys are the attribute names, and the 236 * values are the attribute values. 237 */ 238 this.attrs = {}; // default value just to get the above doc comment in the ES5 output and documentation generator 239 /** 240 * @cfg {String} innerHTML 241 * 242 * The inner HTML for the tag. 243 */ 244 this.innerHTML = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 245 /** 246 * @protected 247 * @property {RegExp} whitespaceRegex 248 * 249 * Regular expression used to match whitespace in a string of CSS classes. 250 */ 251 this.whitespaceRegex = /\s+/; // default value just to get the above doc comment in the ES5 output and documentation generator 252 this.tagName = cfg.tagName || ''; 253 this.attrs = cfg.attrs || {}; 254 this.innerHTML = cfg.innerHtml || cfg.innerHTML || ''; // accept either the camelCased form or the fully capitalized acronym as in the DOM 255 } 256 /** 257 * Sets the tag name that will be used to generate the tag with. 258 * 259 * @param {String} tagName 260 * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. 261 */ 262 HtmlTag.prototype.setTagName = function (tagName) { 263 this.tagName = tagName; 264 return this; 265 }; 266 /** 267 * Retrieves the tag name. 268 * 269 * @return {String} 270 */ 271 HtmlTag.prototype.getTagName = function () { 272 return this.tagName || ''; 273 }; 274 /** 275 * Sets an attribute on the HtmlTag. 276 * 277 * @param {String} attrName The attribute name to set. 278 * @param {String} attrValue The attribute value to set. 279 * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. 280 */ 281 HtmlTag.prototype.setAttr = function (attrName, attrValue) { 282 var tagAttrs = this.getAttrs(); 283 tagAttrs[attrName] = attrValue; 284 return this; 285 }; 286 /** 287 * Retrieves an attribute from the HtmlTag. If the attribute does not exist, returns `undefined`. 288 * 289 * @param {String} attrName The attribute name to retrieve. 290 * @return {String} The attribute's value, or `undefined` if it does not exist on the HtmlTag. 291 */ 292 HtmlTag.prototype.getAttr = function (attrName) { 293 return this.getAttrs()[attrName]; 294 }; 295 /** 296 * Sets one or more attributes on the HtmlTag. 297 * 298 * @param {Object.<String, String>} attrs A key/value Object (map) of the attributes to set. 299 * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. 300 */ 301 HtmlTag.prototype.setAttrs = function (attrs) { 302 Object.assign(this.getAttrs(), attrs); 303 return this; 304 }; 305 /** 306 * Retrieves the attributes Object (map) for the HtmlTag. 307 * 308 * @return {Object.<String, String>} A key/value object of the attributes for the HtmlTag. 309 */ 310 HtmlTag.prototype.getAttrs = function () { 311 return this.attrs || (this.attrs = {}); 312 }; 313 /** 314 * Sets the provided `cssClass`, overwriting any current CSS classes on the HtmlTag. 315 * 316 * @param {String} cssClass One or more space-separated CSS classes to set (overwrite). 317 * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. 318 */ 319 HtmlTag.prototype.setClass = function (cssClass) { 320 return this.setAttr('class', cssClass); 321 }; 322 /** 323 * Convenience method to add one or more CSS classes to the HtmlTag. Will not add duplicate CSS classes. 324 * 325 * @param {String} cssClass One or more space-separated CSS classes to add. 326 * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. 327 */ 328 HtmlTag.prototype.addClass = function (cssClass) { 329 var classAttr = this.getClass(), whitespaceRegex = this.whitespaceRegex, classes = (!classAttr) ? [] : classAttr.split(whitespaceRegex), newClasses = cssClass.split(whitespaceRegex), newClass; 330 while (newClass = newClasses.shift()) { 331 if (indexOf(classes, newClass) === -1) { 332 classes.push(newClass); 333 } 334 } 335 this.getAttrs()['class'] = classes.join(" "); 336 return this; 337 }; 338 /** 339 * Convenience method to remove one or more CSS classes from the HtmlTag. 340 * 341 * @param {String} cssClass One or more space-separated CSS classes to remove. 342 * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. 343 */ 344 HtmlTag.prototype.removeClass = function (cssClass) { 345 var classAttr = this.getClass(), whitespaceRegex = this.whitespaceRegex, classes = (!classAttr) ? [] : classAttr.split(whitespaceRegex), removeClasses = cssClass.split(whitespaceRegex), removeClass; 346 while (classes.length && (removeClass = removeClasses.shift())) { 347 var idx = indexOf(classes, removeClass); 348 if (idx !== -1) { 349 classes.splice(idx, 1); 350 } 351 } 352 this.getAttrs()['class'] = classes.join(" "); 353 return this; 354 }; 355 /** 356 * Convenience method to retrieve the CSS class(es) for the HtmlTag, which will each be separated by spaces when 357 * there are multiple. 358 * 359 * @return {String} 360 */ 361 HtmlTag.prototype.getClass = function () { 362 return this.getAttrs()['class'] || ""; 363 }; 364 /** 365 * Convenience method to check if the tag has a CSS class or not. 366 * 367 * @param {String} cssClass The CSS class to check for. 368 * @return {Boolean} `true` if the HtmlTag has the CSS class, `false` otherwise. 369 */ 370 HtmlTag.prototype.hasClass = function (cssClass) { 371 return (' ' + this.getClass() + ' ').indexOf(' ' + cssClass + ' ') !== -1; 372 }; 373 /** 374 * Sets the inner HTML for the tag. 375 * 376 * @param {String} html The inner HTML to set. 377 * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. 378 */ 379 HtmlTag.prototype.setInnerHTML = function (html) { 380 this.innerHTML = html; 381 return this; 382 }; 383 /**
384 * Backwards compatibility method name. 385 * 386 * @param {String} html The inner HTML to set. 387 * @return {Autolinker.HtmlTag} This HtmlTag instance, so that method calls may be chained. 388 */ 389 HtmlTag.prototype.setInnerHtml = function (html) { 390 return this.setInnerHTML(html); 391 }; 392 /** 393 * Retrieves the inner HTML for the tag. 394 * 395 * @return {String} 396 */ 397 HtmlTag.prototype.getInnerHTML = function () { 398 return this.innerHTML || ""; 399 }; 400 /** 401 * Backward compatibility method name. 402 * 403 * @return {String} 404 */ 405 HtmlTag.prototype.getInnerHtml = function () { 406 return this.getInnerHTML(); 407 }; 408 /** 409 * Override of superclass method used to generate the HTML string for the tag. 410 * 411 * @return {String} 412 */ 413 HtmlTag.prototype.toAnchorString = function () { 414 var tagName = this.getTagName(), attrsStr = this.buildAttrsStr(); 415 attrsStr = (attrsStr) ? ' ' + attrsStr : ''; // prepend a space if there are actually attributes 416 return ['<', tagName, attrsStr, '>', this.getInnerHtml(), '</', tagName, '>'].join(""); 417 }; 418 /** 419 * Support method for {@link #toAnchorString}, returns the string space-separated key="value" pairs, used to populate 420 * the stringified HtmlTag. 421 * 422 * @protected 423 * @return {String} Example return: `attr1="value1" attr2="value2"` 424 */ 425 HtmlTag.prototype.buildAttrsStr = function () { 426 if (!this.attrs) 427 return ""; // no `attrs` Object (map) has been set, return empty string 428 var attrs = this.getAttrs(), attrsArr = []; 429 for (var prop in attrs) { 430 if (attrs.hasOwnProperty(prop)) {
vendor: 10,810 bytes, lines 431-700
431 attrsArr.push(prop + '="' + attrs[prop] + '"'); 432 } 433 } 434 return attrsArr.join(" "); 435 }; 436 return HtmlTag; 437 }()); 438 439 /** 440 * Date: 2015-10-05 441 * Author: Kasper Søfren <[email protected]> (https://github.com/kafoso) 442 * 443 * A truncation feature, where the ellipsis will be placed at a section within 444 * the URL making it still somewhat human readable. 445 * 446 * @param {String} url A URL. 447 * @param {Number} truncateLen The maximum length of the truncated output URL string. 448 * @param {String} ellipsisChars The characters to place within the url, e.g. "...". 449 * @return {String} The truncated URL. 450 */ 451 function truncateSmart(url, truncateLen, ellipsisChars) { 452 var ellipsisLengthBeforeParsing; 453 var ellipsisLength; 454 if (ellipsisChars == null) { 455 ellipsisChars = '…'; 456 ellipsisLength = 3; 457 ellipsisLengthBeforeParsing = 8; 458 } 459 else { 460 ellipsisLength = ellipsisChars.length; 461 ellipsisLengthBeforeParsing = ellipsisChars.length; 462 } 463 var parse_url = function (url) { 464 var urlObj = {}; 465 var urlSub = url; 466 var match = urlSub.match(/^([a-z]+):\/\//i); 467 if (match) { 468 urlObj.scheme = match[1]; 469 urlSub = urlSub.substr(match[0].length); 470 } 471 match = urlSub.match(/^(.*?)(?=(\?|#|\/|$))/i); 472 if (match) { 473 urlObj.host = match[1]; 474 urlSub = urlSub.substr(match[0].length); 475 } 476 match = urlSub.match(/^\/(.*?)(?=(\?|#|$))/i); 477 if (match) { 478 urlObj.path = match[1]; 479 urlSub = urlSub.substr(match[0].length); 480 } 481 match = urlSub.match(/^\?(.*?)(?=(#|$))/i); 482 if (match) { 483 urlObj.query = match[1]; 484 urlSub = urlSub.substr(match[0].length); 485 } 486 match = urlSub.match(/^#(.*?)$/i); 487 if (match) { 488 urlObj.fragment = match[1]; 489 //urlSub = urlSub.substr(match[0].length); -- not used. Uncomment if adding another block. 490 } 491 return urlObj; 492 }; 493 var buildUrl = function (urlObj) { 494 var url = ""; 495 if (urlObj.scheme && urlObj.host) { 496 url += urlObj.scheme + "://"; 497 } 498 if (urlObj.host) { 499 url += urlObj.host; 500 } 501 if (urlObj.path) { 502 url += "/" + urlObj.path; 503 } 504 if (urlObj.query) { 505 url += "?" + urlObj.query; 506 } 507 if (urlObj.fragment) { 508 url += "#" + urlObj.fragment; 509 } 510 return url; 511 }; 512 var buildSegment = function (segment, remainingAvailableLength) { 513 var remainingAvailableLengthHalf = remainingAvailableLength / 2, startOffset = Math.ceil(remainingAvailableLengthHalf), endOffset = (-1) * Math.floor(remainingAvailableLengthHalf), end = ""; 514 if (endOffset < 0) { 515 end = segment.substr(endOffset); 516 } 517 return segment.substr(0, startOffset) + ellipsisChars + end; 518 }; 519 if (url.length <= truncateLen) { 520 return url; 521 } 522 var availableLength = truncateLen - ellipsisLength; 523 var urlObj = parse_url(url); 524 // Clean up the URL 525 if (urlObj.query) { 526 var matchQuery = urlObj.query.match(/^(.*?)(?=(\?|\#))(.*?)$/i); 527 if (matchQuery) { 528 // Malformed URL; two or more "?". Removed any content behind the 2nd. 529 urlObj.query = urlObj.query.substr(0, matchQuery[1].length); 530 url = buildUrl(urlObj); 531 } 532 } 533 if (url.length <= truncateLen) { 534 return url; 535 } 536 if (urlObj.host) { 537 urlObj.host = urlObj.host.replace(/^www\./, ""); 538 url = buildUrl(urlObj); 539 } 540 if (url.length <= truncateLen) { 541 return url; 542 } 543 // Process and build the URL 544 var str = ""; 545 if (urlObj.host) { 546 str += urlObj.host; 547 } 548 if (str.length >= availableLength) { 549 if (urlObj.host.length == truncateLen) { 550 return (urlObj.host.substr(0, (truncateLen - ellipsisLength)) + ellipsisChars).substr(0, availableLength + ellipsisLengthBeforeParsing); 551 } 552 return buildSegment(str, availableLength).substr(0, availableLength + ellipsisLengthBeforeParsing); 553 } 554 var pathAndQuery = ""; 555 if (urlObj.path) { 556 pathAndQuery += "/" + urlObj.path; 557 } 558 if (urlObj.query) { 559 pathAndQuery += "?" + urlObj.query; 560 } 561 if (pathAndQuery) { 562 if ((str + pathAndQuery).length >= availableLength) { 563 if ((str + pathAndQuery).length == truncateLen) { 564 return (str + pathAndQuery).substr(0, truncateLen); 565 } 566 var remainingAvailableLength = availableLength - str.length; 567 return (str + buildSegment(pathAndQuery, remainingAvailableLength)).substr(0, availableLength + ellipsisLengthBeforeParsing); 568 } 569 else { 570 str += pathAndQuery; 571 } 572 } 573 if (urlObj.fragment) { 574 var fragment = "#" + urlObj.fragment; 575 if ((str + fragment).length >= availableLength) { 576 if ((str + fragment).length == truncateLen) { 577 return (str + fragment).substr(0, truncateLen); 578 } 579 var remainingAvailableLength2 = availableLength - str.length; 580 return (str + buildSegment(fragment, remainingAvailableLength2)).substr(0, availableLength + ellipsisLengthBeforeParsing); 581 } 582 else { 583 str += fragment; 584 } 585 } 586 if (urlObj.scheme && urlObj.host) { 587 var scheme = urlObj.scheme + "://"; 588 if ((str + scheme).length < availableLength) { 589 return (scheme + str).substr(0, truncateLen); 590 } 591 } 592 if (str.length <= truncateLen) { 593 return str; 594 } 595 var end = ""; 596 if (availableLength > 0) { 597 end = str.substr((-1) * Math.floor(availableLength / 2)); 598 } 599 return (str.substr(0, Math.ceil(availableLength / 2)) + ellipsisChars + end).substr(0, availableLength + ellipsisLengthBeforeParsing); 600 } 601 602 /** 603 * Date: 2015-10-05 604 * Author: Kasper Søfren <[email protected]> (https://github.com/kafoso) 605 * 606 * A truncation feature, where the ellipsis will be placed in the dead-center of the URL. 607 * 608 * @param {String} url A URL. 609 * @param {Number} truncateLen The maximum length of the truncated output URL string. 610 * @param {String} ellipsisChars The characters to place within the url, e.g. "..". 611 * @return {String} The truncated URL. 612 */ 613 function truncateMiddle(url, truncateLen, ellipsisChars) { 614 if (url.length <= truncateLen) { 615 return url; 616 } 617 var ellipsisLengthBeforeParsing; 618 var ellipsisLength; 619 if (ellipsisChars == null) { 620 ellipsisChars = '…'; 621 ellipsisLengthBeforeParsing = 8; 622 ellipsisLength = 3; 623 } 624 else { 625 ellipsisLengthBeforeParsing = ellipsisChars.length; 626 ellipsisLength = ellipsisChars.length; 627 } 628 var availableLength = truncateLen - ellipsisLength; 629 var end = ""; 630 if (availableLength > 0) { 631 end = url.substr((-1) * Math.floor(availableLength / 2)); 632 } 633 return (url.substr(0, Math.ceil(availableLength / 2)) + ellipsisChars + end).substr(0, availableLength + ellipsisLengthBeforeParsing); 634 } 635 636 /** 637 * A truncation feature where the ellipsis will be placed at the end of the URL. 638 * 639 * @param {String} anchorText 640 * @param {Number} truncateLen The maximum length of the truncated output URL string. 641 * @param {String} ellipsisChars The characters to place within the url, e.g. "..". 642 * @return {String} The truncated URL. 643 */ 644 function truncateEnd(anchorText, truncateLen, ellipsisChars) { 645 return ellipsis(anchorText, truncateLen, ellipsisChars); 646 } 647 648 /** 649 * @protected 650 * @class Autolinker.AnchorTagBuilder 651 * @extends Object 652 * 653 * Builds anchor (<a>) tags for the Autolinker utility when a match is 654 * found. 655 * 656 * Normally this class is instantiated, configured, and used internally by an 657 * {@link Autolinker} instance, but may actually be used indirectly in a 658 * {@link Autolinker#replaceFn replaceFn} to create {@link Autolinker.HtmlTag HtmlTag} 659 * instances which may be modified before returning from the 660 * {@link Autolinker#replaceFn replaceFn}. For example: 661 * 662 * var html = Autolinker.link( "Test google.com", { 663 * replaceFn : function( match ) { 664 * var tag = match.buildTag(); // returns an {@link Autolinker.HtmlTag} instance 665 * tag.setAttr( 'rel', 'nofollow' ); 666 * 667 * return tag; 668 * } 669 * } ); 670 * 671 * // generated html: 672 * // Test <a href="http://google.com" target="_blank" rel="nofollow">google.com</a> 673 */ 674 var AnchorTagBuilder = /** @class */ (function () { 675 /** 676 * @method constructor 677 * @param {Object} [cfg] The configuration options for the AnchorTagBuilder instance, specified in an Object (map). 678 */ 679 function AnchorTagBuilder(cfg) { 680 if (cfg === void 0) { cfg = {}; } 681 /** 682 * @cfg {Boolean} newWindow 683 * @inheritdoc Autolinker#newWindow 684 */ 685 this.newWindow = false; // default value just to get the above doc comment in the ES5 output and documentation generator 686 /** 687 * @cfg {Object} truncate 688 * @inheritdoc Autolinker#truncate 689 */ 690 this.truncate = {}; // default value just to get the above doc comment in the ES5 output and documentation generator 691 /** 692 * @cfg {String} className 693 * @inheritdoc Autolinker#className 694 */ 695 this.className = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 696 this.newWindow = cfg.newWindow || false; 697 this.truncate = cfg.truncate || {}; 698 this.className = cfg.className || ''; 699 } 700 /**
701 * Generates the actual anchor (<a>) tag to use in place of the 702 * matched text, via its `match` object. 703 * 704 * @param {Autolinker.match.Match} match The Match instance to generate an 705 * anchor tag from. 706 * @return {Autolinker.HtmlTag} The HtmlTag instance for the anchor tag. 707 */ 708 AnchorTagBuilder.prototype.build = function (match) { 709 return new HtmlTag({ 710 tagName: 'a', 711 attrs: this.createAttrs(match), 712 innerHtml: this.processAnchorText(match.getAnchorText()) 713 }); 714 }; 715 /** 716 * Creates the Object (map) of the HTML attributes for the anchor (<a>) 717 * tag being generated. 718 * 719 * @protected 720 * @param {Autolinker.match.Match} match The Match instance to generate an 721 * anchor tag from. 722 * @return {Object} A key/value Object (map) of the anchor tag's attributes. 723 */ 724 AnchorTagBuilder.prototype.createAttrs = function (match) { 725 var attrs = { 726 'href': match.getAnchorHref() // we'll always have the `href` attribute 727 }; 728 var cssClass = this.createCssClass(match); 729 if (cssClass) { 730 attrs['class'] = cssClass; 731 } 732 if (this.newWindow) { 733 attrs['target'] = "_blank"; 734 attrs['rel'] = "noopener noreferrer"; // Issue #149. See https://mathiasbynens.github.io/rel-noopener/ 735 } 736 if (this.truncate) { 737 if (this.truncate.length && this.truncate.length < match.getAnchorText().length) { 738 attrs['title'] = match.getAnchorHref(); 739 } 740 } 741 return attrs; 742 }; 743 /** 744 * Creates the CSS class that will be used for a given anchor tag, based on 745 * the `matchType` and the {@link #className} config. 746 * 747 * Example returns: 748 * 749 * - "" // no {@link #className} 750 * - "myLink myLink-url" // url match 751 * - "myLink myLink-email" // email match 752 * - "myLink myLink-phone" // phone match 753 * - "myLink myLink-hashtag" // hashtag match 754 * - "myLink myLink-mention myLink-twitter" // mention match with Twitter service 755 * 756 * @protected 757 * @param {Autolinker.match.Match} match The Match instance to generate an 758 * anchor tag from. 759 * @return {String} The CSS class string for the link. Example return: 760 * "myLink myLink-url". If no {@link #className} was configured, returns 761 * an empty string. 762 */ 763 AnchorTagBuilder.prototype.createCssClass = function (match) { 764 var className = this.className; 765 if (!className) { 766 return ""; 767 } 768 else { 769 var returnClasses = [className], cssClassSuffixes = match.getCssClassSuffixes(); 770 for (var i = 0, len = cssClassSuffixes.length; i < len; i++) { 771 returnClasses.push(className + '-' + cssClassSuffixes[i]); 772 } 773 return returnClasses.join(' '); 774 } 775 }; 776 /** 777 * Processes the `anchorText` by truncating the text according to the 778 * {@link #truncate} config. 779 * 780 * @private 781 * @param {String} anchorText The anchor tag's text (i.e. what will be 782 * displayed). 783 * @return {String} The processed `anchorText`. 784 */ 785 AnchorTagBuilder.prototype.processAnchorText = function (anchorText) { 786 anchorText = this.doTruncate(anchorText); 787 return anchorText; 788 }; 789 /** 790 * Performs the truncation of the `anchorText` based on the {@link #truncate} 791 * option. If the `anchorText` is longer than the length specified by the 792 * {@link #truncate} option, the truncation is performed based on the 793 * `location` property. See {@link #truncate} for details. 794 * 795 * @private 796 * @param {String} anchorText The anchor tag's text (i.e. what will be 797 * displayed). 798 * @return {String} The truncated anchor text. 799 */ 800 AnchorTagBuilder.prototype.doTruncate = function (anchorText) { 801 var truncate = this.truncate; 802 if (!truncate || !truncate.length) 803 return anchorText; 804 var truncateLength = truncate.length, truncateLocation = truncate.location; 805 if (truncateLocation === 'smart') { 806 return truncateSmart(anchorText, truncateLength); 807 } 808 else if (truncateLocation === 'middle') { 809 return truncateMiddle(anchorText, truncateLength); 810 } 811 else { 812 return truncateEnd(anchorText, truncateLength); 813 } 814 }; 815 return AnchorTagBuilder; 816 }()); 817 818 /** 819 * @abstract 820 * @class Autolinker.match.Match 821 * 822 * Represents a match found in an input string which should be Autolinked. A Match object is what is provided in a 823 * {@link Autolinker#replaceFn replaceFn}, and may be used to query for details about the match. 824 * 825 * For example: 826 * 827 * var input = "..."; // string with URLs, Email Addresses, and Mentions (Twitter, Instagram, Soundcloud) 828 * 829 * var linkedText = Autolinker.link( input, { 830 * replaceFn : function( match ) { 831 * console.log( "href = ", match.getAnchorHref() ); 832 * console.log( "text = ", match.getAnchorText() ); 833 * 834 * switch( match.getType() ) { 835 * case 'url' : 836 * console.log( "url: ", match.getUrl() ); 837 * 838 * case 'email' : 839 * console.log( "email: ", match.getEmail() ); 840 * 841 * case 'mention' : 842 * console.log( "mention: ", match.getMention() ); 843 * } 844 * } 845 * } ); 846 * 847 * See the {@link Autolinker} class for more details on using the {@link Autolinker#replaceFn replaceFn}. 848 */ 849 var Match = /** @class */ (function () { 850 /** 851 * @member Autolinker.match.Match 852 * @method constructor 853 * @param {Object} cfg The configuration properties for the Match 854 * instance, specified in an Object (map). 855 */ 856 function Match(cfg) { 857 /** 858 * @cfg {Autolinker.AnchorTagBuilder} tagBuilder (required) 859 * 860 * Reference to the AnchorTagBuilder instance to use to generate an anchor 861 * tag for the Match. 862 */ 863 this.__jsduckDummyDocProp = null; // property used just to get the above doc comment into the ES5 output and documentation generator 864 /** 865 * @cfg {String} matchedText (required) 866 * 867 * The original text that was matched by the {@link Autolinker.matcher.Matcher}. 868 */ 869 this.matchedText = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 870 /** 871 * @cfg {Number} offset (required) 872 * 873 * The offset of where the match was made in the input string. 874 */ 875 this.offset = 0; // default value just to get the above doc comment in the ES5 output and documentation generator 876 this.tagBuilder = cfg.tagBuilder; 877 this.matchedText = cfg.matchedText; 878 this.offset = cfg.offset; 879 } 880 /** 881 * Returns the original text that was matched. 882 * 883 * @return {String} 884 */ 885 Match.prototype.getMatchedText = function () { 886 return this.matchedText; 887 }; 888 /** 889 * Sets the {@link #offset} of where the match was made in the input string. 890 * 891 * A {@link Autolinker.matcher.Matcher} will be fed only HTML text nodes, 892 * and will therefore set an original offset that is relative to the HTML 893 * text node itself. However, we want this offset to be relative to the full 894 * HTML input string, and thus if using {@link Autolinker#parse} (rather 895 * than calling a {@link Autolinker.matcher.Matcher} directly), then this 896 * offset is corrected after the Matcher itself has done its job. 897 * 898 * @param {Number} offset 899 */ 900 Match.prototype.setOffset = function (offset) { 901 this.offset = offset; 902 }; 903 /** 904 * Returns the offset of where the match was made in the input string. This 905 * is the 0-based index of the match. 906 * 907 * @return {Number} 908 */ 909 Match.prototype.getOffset = function () { 910 return this.offset; 911 }; 912 /** 913 * Returns the CSS class suffix(es) for this match. 914 *
915 * A CSS class suffix is appended to the {@link Autolinker#className} in 916 * the {@link Autolinker.AnchorTagBuilder} when a match is translated into 917 * an anchor tag. 918 * 919 * For example, if {@link Autolinker#className} was configured as 'myLink', 920 * and this method returns `[ 'url' ]`, the final class name of the element 921 * will become: 'myLink myLink-url'. 922 * 923 * The match may provide multiple CSS class suffixes to be appended to the 924 * {@link Autolinker#className} in order to facilitate better styling 925 * options for different match criteria. See {@link Autolinker.match.Mention} 926 * for an example. 927 * 928 * By default, this method returns a single array with the match's 929 * {@link #getType type} name, but may be overridden by subclasses. 930 * 931 * @return {String[]} 932 */ 933 Match.prototype.getCssClassSuffixes = function () { 934 return [this.getType()]; 935 }; 936 /** 937 * Builds and returns an {@link Autolinker.HtmlTag} instance based on the 938 * Match. 939 * 940 * This can be used to easily generate anchor tags from matches, and either 941 * return their HTML string, or modify them before doing so. 942 * 943 * Example Usage: 944 * 945 * var tag = match.buildTag(); 946 * tag.addClass( 'cordova-link' ); 947 * tag.setAttr( 'target', '_system' ); 948 * 949 * tag.toAnchorString(); // <a href="http://google.com" class="cordova-link" target="_system">Google</a> 950 * 951 * Example Usage in {@link Autolinker#replaceFn}: 952 * 953 * var html = Autolinker.link( "Test google.com", { 954 * replaceFn : function( match ) { 955 * var tag = match.buildTag(); // returns an {@link Autolinker.HtmlTag} instance 956 * tag.setAttr( 'rel', 'nofollow' ); 957 * 958 * return tag; 959 * } 960 * } ); 961 * 962 * // generated html: 963 * // Test <a href="http://google.com" target="_blank" rel="nofollow">google.com</a> 964 */ 965 Match.prototype.buildTag = function () { 966 return this.tagBuilder.build(this); 967 }; 968 return Match; 969 }()); 970 971 /*! ***************************************************************************** 972 Copyright (c) Microsoft Corporation. All rights reserved. 973 Licensed under the Apache License, Version 2.0 (the "License"); you may not use 974 this file except in compliance with the License. You may obtain a copy of the 975 License at http://www.apache.org/licenses/LICENSE-2.0 976 977 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 978 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 979 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 980 MERCHANTABLITY OR NON-INFRINGEMENT. 981 982 See the Apache Version 2.0 License for specific language governing permissions 983 and limitations under the License. 984 ***************************************************************************** */ 985 /* global Reflect, Promise */ 986 987 var extendStatics = function(d, b) { 988 extendStatics = Object.setPrototypeOf || 989 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 990 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 991 return extendStatics(d, b); 992 }; 993 994 function __extends(d, b) { 995 extendStatics(d, b); 996 function __() { this.constructor = d; } 997 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 998 } 999 1000 var __assign = function() { 1001 __assign = Object.assign || function __assign(t) { 1002 for (var s, i = 1, n = arguments.length; i < n; i++) { 1003 s = arguments[i]; 1004 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; 1005 } 1006 return t; 1007 }; 1008 return __assign.apply(this, arguments); 1009 }; 1010 1011 /** 1012 * @class Autolinker.match.Email 1013 * @extends Autolinker.match.Match 1014 * 1015 * Represents a Email match found in an input string which should be Autolinked. 1016 * 1017 * See this class's superclass ({@link Autolinker.match.Match}) for more details. 1018 */ 1019 var EmailMatch = /** @class */ (function (_super) { 1020 __extends(EmailMatch, _super); 1021 /** 1022 * @method constructor 1023 * @param {Object} cfg The configuration properties for the Match 1024 * instance, specified in an Object (map). 1025 */ 1026 function EmailMatch(cfg) { 1027 var _this = _super.call(this, cfg) || this; 1028 /** 1029 * @cfg {String} email (required) 1030 * 1031 * The email address that was matched. 1032 */ 1033 _this.email = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 1034 _this.email = cfg.email; 1035 return _this; 1036 } 1037 /** 1038 * Returns a string name for the type of match that this class represents. 1039 * For the case of EmailMatch, returns 'email'. 1040 * 1041 * @return {String} 1042 */ 1043 EmailMatch.prototype.getType = function () { 1044 return 'email'; 1045 }; 1046 /** 1047 * Returns the email address that was matched. 1048 * 1049 * @return {String} 1050 */ 1051 EmailMatch.prototype.getEmail = function () { 1052 return this.email; 1053 }; 1054 /**
1055 * Returns the anchor href that should be generated for the match. 1056 * 1057 * @return {String} 1058 */ 1059 EmailMatch.prototype.getAnchorHref = function () { 1060 return 'mailto:' + this.email; 1061 }; 1062 /** 1063 * Returns the anchor text that should be generated for the match. 1064 * 1065 * @return {String} 1066 */ 1067 EmailMatch.prototype.getAnchorText = function () { 1068 return this.email; 1069 }; 1070 return EmailMatch; 1071 }(Match)); 1072 1073 /** 1074 * @class Autolinker.match.Hashtag 1075 * @extends Autolinker.match.Match 1076 * 1077 * Represents a Hashtag match found in an input string which should be 1078 * Autolinked. 1079 * 1080 * See this class's superclass ({@link Autolinker.match.Match}) for more 1081 * details. 1082 */ 1083 var HashtagMatch = /** @class */ (function (_super) { 1084 __extends(HashtagMatch, _super); 1085 /** 1086 * @method constructor 1087 * @param {Object} cfg The configuration properties for the Match 1088 * instance, specified in an Object (map). 1089 */ 1090 function HashtagMatch(cfg) { 1091 var _this = _super.call(this, cfg) || this; 1092 /** 1093 * @cfg {String} serviceName 1094 * 1095 * The service to point hashtag matches to. See {@link Autolinker#hashtag} 1096 * for available values. 1097 */ 1098 _this.serviceName = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 1099 /** 1100 * @cfg {String} hashtag (required) 1101 * 1102 * The HashtagMatch that was matched, without the '#'. 1103 */ 1104 _this.hashtag = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 1105 _this.serviceName = cfg.serviceName; 1106 _this.hashtag = cfg.hashtag; 1107 return _this; 1108 } 1109 /** 1110 * Returns a string name for the type of match that this class represents. 1111 * For the case of HashtagMatch, returns 'hashtag'. 1112 * 1113 * @return {String} 1114 */ 1115 HashtagMatch.prototype.getType = function () { 1116 return 'hashtag'; 1117 }; 1118 /** 1119 * Returns the configured {@link #serviceName} to point the HashtagMatch to. 1120 * Ex: 'facebook', 'twitter'. 1121 * 1122 * @return {String} 1123 */ 1124 HashtagMatch.prototype.getServiceName = function () { 1125 return this.serviceName; 1126 }; 1127 /** 1128 * Returns the matched hashtag, without the '#' character. 1129 * 1130 * @return {String} 1131 */ 1132 HashtagMatch.prototype.getHashtag = function () { 1133 return this.hashtag; 1134 }; 1135 /** 1136 * Returns the anchor href that should be generated for the match. 1137 * 1138 * @return {String} 1139 */ 1140 HashtagMatch.prototype.getAnchorHref = function () { 1141 var serviceName = this.serviceName, hashtag = this.hashtag; 1142 switch (serviceName) { 1143 case 'twitter': 1144 return 'https://twitter.com/hashtag/' + hashtag; 1145 case 'facebook': 1146 return 'https://www.facebook.com/hashtag/' + hashtag; 1147 case 'instagram': 1148 return 'https://instagram.com/explore/tags/' + hashtag; 1149 default: // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case. 1150 throw new Error('Unknown service name to point hashtag to: ' + serviceName); 1151 } 1152 }; 1153 /** 1154 * Returns the anchor text that should be generated for the match. 1155 * 1156 * @return {String} 1157 */ 1158 HashtagMatch.prototype.getAnchorText = function () { 1159 return '#' + this.hashtag; 1160 }; 1161 return HashtagMatch; 1162 }(Match)); 1163 1164 /** 1165 * @class Autolinker.match.Mention 1166 * @extends Autolinker.match.Match 1167 * 1168 * Represents a Mention match found in an input string which should be Autolinked. 1169 * 1170 * See this class's superclass ({@link Autolinker.match.Match}) for more details. 1171 */ 1172 var MentionMatch = /** @class */ (function (_super) { 1173 __extends(MentionMatch, _super); 1174 /** 1175 * @method constructor 1176 * @param {Object} cfg The configuration properties for the Match 1177 * instance, specified in an Object (map). 1178 */ 1179 function MentionMatch(cfg) { 1180 var _this = _super.call(this, cfg) || this; 1181 /** 1182 * @cfg {String} serviceName 1183 * 1184 * The service to point mention matches to. See {@link Autolinker#mention} 1185 * for available values. 1186 */ 1187 _this.serviceName = 'twitter'; // default value just to get the above doc comment in the ES5 output and documentation generator 1188 /** 1189 * @cfg {String} mention (required) 1190 * 1191 * The Mention that was matched, without the '@' character. 1192 */ 1193 _this.mention = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 1194 _this.mention = cfg.mention; 1195 _this.serviceName = cfg.serviceName; 1196 return _this; 1197 } 1198 /** 1199 * Returns a string name for the type of match that this class represents. 1200 * For the case of MentionMatch, returns 'mention'. 1201 * 1202 * @return {String} 1203 */ 1204 MentionMatch.prototype.getType = function () { 1205 return 'mention'; 1206 }; 1207 /** 1208 * Returns the mention, without the '@' character. 1209 * 1210 * @return {String} 1211 */ 1212 MentionMatch.prototype.getMention = function () { 1213 return this.mention; 1214 }; 1215 /** 1216 * Returns the configured {@link #serviceName} to point the mention to. 1217 * Ex: 'instagram', 'twitter', 'soundcloud'. 1218 * 1219 * @return {String} 1220 */ 1221 MentionMatch.prototype.getServiceName = function () { 1222 return this.serviceName; 1223 }; 1224 /**
1225 * Returns the anchor href that should be generated for the match. 1226 * 1227 * @return {String} 1228 */ 1229 MentionMatch.prototype.getAnchorHref = function () { 1230 switch (this.serviceName) { 1231 case 'twitter': 1232 return 'https://twitter.com/' + this.mention; 1233 case 'instagram': 1234 return 'https://instagram.com/' + this.mention; 1235 case 'soundcloud': 1236 return 'https://soundcloud.com/' + this.mention; 1237 default: // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case. 1238 throw new Error('Unknown service name to point mention to: ' + this.serviceName); 1239 } 1240 }; 1241 /** 1242 * Returns the anchor text that should be generated for the match. 1243 * 1244 * @return {String} 1245 */ 1246 MentionMatch.prototype.getAnchorText = function () { 1247 return '@' + this.mention; 1248 }; 1249 /** 1250 * Returns the CSS class suffixes that should be used on a tag built with 1251 * the match. See {@link Autolinker.match.Match#getCssClassSuffixes} for 1252 * details. 1253 * 1254 * @return {String[]} 1255 */ 1256 MentionMatch.prototype.getCssClassSuffixes = function () { 1257 var cssClassSuffixes = _super.prototype.getCssClassSuffixes.call(this), serviceName = this.getServiceName(); 1258 if (serviceName) { 1259 cssClassSuffixes.push(serviceName); 1260 } 1261 return cssClassSuffixes; 1262 }; 1263 return MentionMatch; 1264 }(Match)); 1265 1266 /** 1267 * @class Autolinker.match.Phone 1268 * @extends Autolinker.match.Match 1269 * 1270 * Represents a Phone number match found in an input string which should be 1271 * Autolinked. 1272 * 1273 * See this class's superclass ({@link Autolinker.match.Match}) for more 1274 * details. 1275 */ 1276 var PhoneMatch = /** @class */ (function (_super) { 1277 __extends(PhoneMatch, _super); 1278 /** 1279 * @method constructor 1280 * @param {Object} cfg The configuration properties for the Match 1281 * instance, specified in an Object (map). 1282 */ 1283 function PhoneMatch(cfg) { 1284 var _this = _super.call(this, cfg) || this; 1285 /** 1286 * @protected 1287 * @property {String} number (required) 1288 * 1289 * The phone number that was matched, without any delimiter characters. 1290 * 1291 * Note: This is a string to allow for prefixed 0's. 1292 */ 1293 _this.number = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 1294 /** 1295 * @protected 1296 * @property {Boolean} plusSign (required) 1297 * 1298 * `true` if the matched phone number started with a '+' sign. We'll include 1299 * it in the `tel:` URL if so, as this is needed for international numbers. 1300 * 1301 * Ex: '+1 (123) 456 7879' 1302 */ 1303 _this.plusSign = false; // default value just to get the above doc comment in the ES5 output and documentation generator 1304 _this.number = cfg.number; 1305 _this.plusSign = cfg.plusSign; 1306 return _this; 1307 } 1308 /** 1309 * Returns a string name for the type of match that this class represents. 1310 * For the case of PhoneMatch, returns 'phone'. 1311 * 1312 * @return {String} 1313 */ 1314 PhoneMatch.prototype.getType = function () { 1315 return 'phone'; 1316 }; 1317 /** 1318 * Returns the phone number that was matched as a string, without any 1319 * delimiter characters. 1320 * 1321 * Note: This is a string to allow for prefixed 0's. 1322 * 1323 * @return {String} 1324 */ 1325 PhoneMatch.prototype.getPhoneNumber = function () { 1326 return this.number; 1327 }; 1328 /** 1329 * Alias of {@link #getPhoneNumber}, returns the phone number that was 1330 * matched as a string, without any delimiter characters. 1331 * 1332 * Note: This is a string to allow for prefixed 0's. 1333 * 1334 * @return {String} 1335 */ 1336 PhoneMatch.prototype.getNumber = function () { 1337 return this.getPhoneNumber(); 1338 }; 1339 /**
1340 * Returns the anchor href that should be generated for the match. 1341 * 1342 * @return {String} 1343 */ 1344 PhoneMatch.prototype.getAnchorHref = function () { 1345 return 'tel:' + (this.plusSign ? '+' : '') + this.number; 1346 }; 1347 /** 1348 * Returns the anchor text that should be generated for the match. 1349 * 1350 * @return {String} 1351 */ 1352 PhoneMatch.prototype.getAnchorText = function () { 1353 return this.matchedText; 1354 }; 1355 return PhoneMatch; 1356 }(Match)); 1357 1358 /** 1359 * @class Autolinker.match.Url 1360 * @extends Autolinker.match.Match 1361 * 1362 * Represents a Url match found in an input string which should be Autolinked. 1363 * 1364 * See this class's superclass ({@link Autolinker.match.Match}) for more details. 1365 */ 1366 var UrlMatch = /** @class */ (function (_super) { 1367 __extends(UrlMatch, _super); 1368 /** 1369 * @method constructor 1370 * @param {Object} cfg The configuration properties for the Match 1371 * instance, specified in an Object (map). 1372 */ 1373 function UrlMatch(cfg) { 1374 var _this = _super.call(this, cfg) || this; 1375 /** 1376 * @cfg {String} url (required) 1377 * 1378 * The url that was matched. 1379 */ 1380 _this.url = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 1381 /** 1382 * @cfg {"scheme"/"www"/"tld"} urlMatchType (required) 1383 * 1384 * The type of URL match that this class represents. This helps to determine 1385 * if the match was made in the original text with a prefixed scheme (ex: 1386 * 'http://www.google.com'), a prefixed 'www' (ex: 'www.google.com'), or 1387 * was matched by a known top-level domain (ex: 'google.com'). 1388 */ 1389 _this.urlMatchType = 'scheme'; // default value just to get the above doc comment in the ES5 output and documentation generator 1390 /** 1391 * @cfg {Boolean} protocolUrlMatch (required) 1392 * 1393 * `true` if the URL is a match which already has a protocol (i.e. 1394 * 'http://'), `false` if the match was from a 'www' or known TLD match. 1395 */ 1396 _this.protocolUrlMatch = false; // default value just to get the above doc comment in the ES5 output and documentation generator 1397 /** 1398 * @cfg {Boolean} protocolRelativeMatch (required) 1399 * 1400 * `true` if the URL is a protocol-relative match. A protocol-relative match 1401 * is a URL that starts with '//', and will be either http:// or https:// 1402 * based on the protocol that the site is loaded under. 1403 */ 1404 _this.protocolRelativeMatch = false; // default value just to get the above doc comment in the ES5 output and documentation generator 1405 /** 1406 * @cfg {Object} stripPrefix (required) 1407 * 1408 * The Object form of {@link Autolinker#cfg-stripPrefix}. 1409 */ 1410 _this.stripPrefix = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator 1411 /** 1412 * @cfg {Boolean} stripTrailingSlash (required) 1413 * @inheritdoc Autolinker#cfg-stripTrailingSlash 1414 */ 1415 _this.stripTrailingSlash = true; // default value just to get the above doc comment in the ES5 output and documentation generator 1416 /** 1417 * @cfg {Boolean} decodePercentEncoding (required) 1418 * @inheritdoc Autolinker#cfg-decodePercentEncoding 1419 */ 1420 _this.decodePercentEncoding = true; // default value just to get the above doc comment in the ES5 output and documentation generator 1421 /** 1422 * @private 1423 * @property {RegExp} schemePrefixRegex 1424 * 1425 * A regular expression used to remove the 'http://' or 'https://' from 1426 * URLs. 1427 */ 1428 _this.schemePrefixRegex = /^(https?:\/\/)?/i; 1429 /** 1430 * @private 1431 * @property {RegExp} wwwPrefixRegex 1432 * 1433 * A regular expression used to remove the 'www.' from URLs. 1434 */ 1435 _this.wwwPrefixRegex = /^(https?:\/\/)?(www\.)?/i; 1436 /** 1437 * @private 1438 * @property {RegExp} protocolRelativeRegex 1439 * 1440 * The regular expression used to remove the protocol-relative '//' from the {@link #url} string, for purposes 1441 * of {@link #getAnchorText}. A protocol-relative URL is, for example, "//yahoo.com" 1442 */ 1443 _this.protocolRelativeRegex = /^\/\//; 1444 /** 1445 * @private 1446 * @property {Boolean} protocolPrepended 1447 * 1448 * Will be set to `true` if the 'http://' protocol has been prepended to the {@link #url} (because the 1449 * {@link #url} did not have a protocol) 1450 */ 1451 _this.protocolPrepended = false;
1452 _this.urlMatchType = cfg.urlMatchType; 1453 _this.url = cfg.url; 1454 _this.protocolUrlMatch = cfg.protocolUrlMatch; 1455 _this.protocolRelativeMatch = cfg.protocolRelativeMatch; 1456 _this.stripPrefix = cfg.stripPrefix; 1457 _this.stripTrailingSlash = cfg.stripTrailingSlash; 1458 _this.decodePercentEncoding = cfg.decodePercentEncoding; 1459 return _this; 1460 } 1461 /** 1462 * Returns a string name for the type of match that this class represents. 1463 * For the case of UrlMatch, returns 'url'. 1464 * 1465 * @return {String} 1466 */ 1467 UrlMatch.prototype.getType = function () { 1468 return 'url'; 1469 }; 1470 /** 1471 * Returns a string name for the type of URL match that this class 1472 * represents. 1473 * 1474 * This helps to determine if the match was made in the original text with a 1475 * prefixed scheme (ex: 'http://www.google.com'), a prefixed 'www' (ex: 1476 * 'www.google.com'), or was matched by a known top-level domain (ex: 1477 * 'google.com'). 1478 * 1479 * @return {"scheme"/"www"/"tld"} 1480 */ 1481 UrlMatch.prototype.getUrlMatchType = function () { 1482 return this.urlMatchType; 1483 }; 1484 /** 1485 * Returns the url that was matched, assuming the protocol to be 'http://' if the original 1486 * match was missing a protocol. 1487 * 1488 * @return {String} 1489 */ 1490 UrlMatch.prototype.getUrl = function () { 1491 var url = this.url; 1492 // if the url string doesn't begin with a protocol, assume 'http://' 1493 if (!this.protocolRelativeMatch && !this.protocolUrlMatch && !this.protocolPrepended) { 1494 url = this.url = 'http://' + url; 1495 this.protocolPrepended = true; 1496 } 1497 return url; 1498 }; 1499 /** 1500 * Returns the anchor href that should be generated for the match. 1501 * 1502 * @return {String} 1503 */ 1504 UrlMatch.prototype.getAnchorHref = function () { 1505 var url = this.getUrl(); 1506 return url.replace(/&/g, '&'); // any &'s in the URL should be converted back to '&' if they were displayed as & in the source html 1507 }; 1508 /** 1509 * Returns the anchor text that should be generated for the match. 1510 * 1511 * @return {String} 1512 */ 1513 UrlMatch.prototype.getAnchorText = function () { 1514 var anchorText = this.getMatchedText(); 1515 if (this.protocolRelativeMatch) { 1516 // Strip off any protocol-relative '//' from the anch
1516or text 1517 anchorText = this.stripProtocolRelativePrefix(anchorText); 1518 } 1519 if (this.stripPrefix.scheme) { 1520 anchorText = this.stripSchemePrefix(anchorText); 1521 } 1522 if (this.stripPrefix.www) { 1523 anchorText = this.stripWwwPrefix(anchorText); 1524 } 1525 if (this.stripTrailingSlash) { 1526 anchorText = this.removeTrailingSlash(anchorText); // remove trailing slash, if there is one 1527 } 1528 if (this.decodePercentEncoding) { 1529 anchorText = this.removePercentEncoding(anchorText); 1530 } 1531 return anchorText; 1532 }; 1533 // --------------------------------------- 1534 // Utility Functionality 1535 /** 1536 * Strips the scheme prefix (such as "http://" or "https://") from the given 1537 * `url`. 1538 * 1539 * @private 1540 * @param {String} url The text of the anchor that is being generated, for 1541 * which to strip off the url scheme. 1542 * @return {String} The `url`, with the scheme stripped. 1543 */ 1544 UrlMatch.prototype.stripSchemePrefix = function (url) { 1545 return url.replace(this.schemePrefixRegex, ''); 1546 }; 1547 /** 1548 * Strips the 'www' prefix from the given `url`. 1549 * 1550 * @private 1551 * @param {String} url The text of the anchor that is being generated, for 1552 * which to strip off the 'www' if it exists. 1553 * @return {String} The `url`, with the 'www' stripped. 1554 */ 1555 UrlMatch.prototype.stripWwwPrefix = function (url) { 1556 return url.replace(this.wwwPrefixRegex, '$1'); // leave any scheme ($1), it one exists 1557 }; 1558 /**
1559 * Strips any protocol-relative '//' from the anchor text. 1560 * 1561 * @private 1562 * @param {String} text The text of the anchor that is being generated, for which to strip off the 1563 * protocol-relative prefix (such as stripping off "//") 1564 * @return {String} The `anchorText`, with the protocol-relative prefix stripped. 1565 */ 1566 UrlMatch.prototype.stripProtocolRelativePrefix = function (text) { 1567 return text.replace(this.protocolRelativeRegex, ''); 1568 }; 1569 /** 1570 * Removes any trailing slash from the given `anchorText`, in preparation for the text to be displayed. 1571 * 1572 * @private 1573 * @param {String} anchorText The text of the anchor that is being generated, for which to remove any trailing 1574 * slash ('/') that may exist. 1575 * @return {String} The `anchorText`, with the trailing slash removed. 1576 */ 1577 UrlMatch.prototype.removeTrailingSlash = function (anchorText) { 1578 if (anchorText.charAt(anchorText.length - 1) === '/') { 1579 anchorText = anchorText.slice(0, -1); 1580 } 1581 return anchorText; 1582 }; 1583 /** 1584 * Decodes percent-encoded characters from the given `anchorText`, in 1585 * preparation for the text to be displayed. 1586 * 1587 * @private 1588 * @param {String} anchorText The text of the anchor that is being 1589 * generated, for which to decode any percent-encoded characters. 1590 * @return {String} The `anchorText`, with the percent-encoded characters 1591 * decoded. 1592 */ 1593 UrlMatch.prototype.removePercentEncoding = function (anchorText) { 1594 // First, convert a few of the known % encodings to the corresponding 1595 // HTML entities that could accidentally be interpretted as special 1596 // HTML characters 1597 var preProcessedEntityAnchorText = anchorText 1598 .replace(/%22/gi, '"') // " char 1599 .replace(/%26/gi, '&') // & char 1600 .replace(/%27/gi, ''') // ' char 1601 .replace(/%3C/gi, '<') // < char 1602 .replace(/%3E/gi, '>'); // > char 1603 try { 1604 // Now attempt to decode the rest of the anchor text 1605 return decodeURIComponent(preProcessedEntityAnchorText); 1606 } 1607 catch (e) { // Invalid % escape sequence in the anchor text 1608 return preProcessedEntityAnchorText; 1609 } 1610 }; 1611 return UrlMatch; 1612 }(Match)); 1613 1614 /** 1615 * @abstract 1616 * @class Autolinker.matcher.Matcher 1617 * 1618 * An abstract class and interface for individual matchers to find matches in 1619 * an input string with linkified versions of them. 1620 * 1621 * Note that Matchers do not take HTML into account - they must be fed the text 1622 * nodes of any HTML string, which is handled by {@link Autolinker#parse}. 1623 */ 1624 var Matcher = /** @class */ (function () { 1625 /** 1626 * @method constructor 1627 * @param {Object} cfg The configuration properties for the Matcher 1628 * instance, specified in an Object (map). 1629 */ 1630 function Matcher(cfg) { 1631 /** 1632 * @cfg {Autolinker.AnchorTagBuilder} tagBuilder (required) 1633 * 1634 * Reference to the AnchorTagBuilder instance to use to generate HTML tags 1635 * for {@link Autolinker.match.Match Matches}. 1636 */ 1637 this.__jsduckDummyDocProp = null; // property used just to get the above doc comment into the ES5 output and documentation generator 1638 this.tagBuilder = cfg.tagBuilder; 1639 } 1640 return Matcher; 1641 }()); 1642 1643 /* 1644 * This file builds and stores a library of the common regular expressions used 1645 * by the Autolinker utility. 1646 * 1647 * Other regular expressions may exist ad-hoc, but these are generally the 1648 * regular expressions that are shared between source files. 1649 */ 1650 /** 1651 * Regular expression to match upper and lowercase ASCII letters 1652 */ 1653 var letterRe = /[A-Za-z]/; 1654 /** 1655 * Regular expression to match ASCII digits 1656 */ 1657 var digitRe = /[\d]/; 1658 /** 1659 * Regular expression to match everything *except* ASCII digits 1660 */ 1661 var nonDigitRe = /[\D]/; 1662 /** 1663 * Regular expression to match whitespace 1664 */ 1665 var whitespaceRe = /\s/; 1666 /** 1667 * Regular expression to match quote characters 1668 */ 1669 var quoteRe = /['"]/; 1670 /** 1671 * Regular expression to match the range of ASCII control characters (0-31), and 1672 * the backspace char (127) 1673 */ 1674 var controlCharsRe = /[\x00-\x1F\x7F]/; 1675 /** 1676 * The string form of a regular expression that would match all of the 1677 * alphabetic ("letter") chars in the unicode character set when placed in a 1678 * RegExp character class (`[]`). This includes all international alphabetic 1679 * characters. 1680 * 1681 * These would be the characters matched by unicode regex engines `\p{L}` 1682 * escape ("all letters"). 1683 * 1684 * Taken from the XRegExp library: http://xregexp.com/ (thanks @https://github.com/slevithan) 1685 * Specifically: http://xregexp.com/v/3.2.0/xregexp-all.js, the 'Letter' 1686 * regex's bmp 1687 * 1688 * VERY IMPORTANT: This set of characters is defined inside of a Regular 1689 * Expression literal rather than a string literal to prevent UglifyJS from 1690 * compressing the unicode escape sequences into their actual unicode 1691 * characters. If Uglify compresses these into the unicode characters 1692 * themselves, this results in the error "Range out of order in character 1693 * class" when these characters are used inside of a Regular Expression 1694 * character class (`[]`). See usages of this const. Alternatively, we can set 1695 * the UglifyJS option `ascii_only` to true for the build, but that doesn't 1696 * help others who are pulling in Autolinker into their own build and running 1697 * UglifyJS themselves. 1698 */ 1699 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\u
16990EB3\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/ 1700 .source; // see note in above variable description 1701 /** 1702 * The string form of a regular expression that would match all emoji characters 1703 * Based on the emoji regex defined in this article: https://thekevinscott.com/emojis-in-javascript/ 1704 */ 1705 var emojiStr = /\u2700-\u27bf\udde6-\uddff\ud800-\udbff\udc00-\udfff\ufe0e\ufe0f\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0\ud83c\udffb-\udfff\u200d\u3299\u3297\u303d\u3030\u24c2\ud83c\udd70-\udd71\udd7e-\udd7f\udd8e\udd91-\udd9a\udde6-\uddff\ude01-\ude02\ude1a\ude2f\ude32-\ude3a\ude50-\ude51\u203c\u2049\u25aa-\u25ab\u25b6\u25c0\u25fb-\u25fe\u00a9\u00ae\u2122\u2139\udc04\u2600-\u26FF\u2b05\u2b06\u2b07\u2b1b\u2b1c\u2b50\u2b55\u231a\u231b\u2328\u23cf\u23e9-\u23f3\u23f8-\u23fa\udccf\u2935\u2934\u2190-\u21ff/ 1706 .source; 1707 /** 1708 * The string form of a regular expression that would match all of the 1709 * combining mark characters in the unicode character set when placed in a 1710 * RegExp character class (`[]`). 1711 * 1712 * These would be the characters matched by unicode regex engines `\p{M}` 1713 * escape ("all marks"). 1714 * 1715 * Taken from the XRegExp library: http://xregexp.com/ (thanks @https://github.com/slevithan) 1716 * Specifically: http://xregexp.com/v/3.2.0/xregexp-all.js, the 'Mark' 1717 * regex's bmp 1718 * 1719 * VERY IMPORTANT: This set of characters is defined inside of a Regular 1720 * Expression literal rather than a string literal to prevent UglifyJS from 1721 * compressing the unicode escape sequences into their actual unicode 1722 * characters. If Uglify compresses these into the unicode characters 1723 * themselves, this results in the error "Range out of order in character 1724 * class" when these characters are used inside of a Regular Expression 1725 * character class (`[]`). See usages of this const. Alternatively, we can set 1726 * the UglifyJS option `ascii_only` to true for the build, but that doesn't 1727 * help others who are pulling in Autolinker into their own build and running 1728 * UglifyJS themselves. 1729 */
1730 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/ 1731 .source; // see note in above variable description 1732 /** 1733 * The string form of a regular expression that would match all of the 1734 * alphabetic ("letter") chars, emoji, and combining marks in the unicode character set 1735 * when placed in a RegExp character class (`[]`). This includes all 1736 * international alphabetic characters. 1737 * 1738 * These would be the characters matched by unicode regex engines `\p{L}\p{M}` 1739 * escapes and emoji characters. 1740 */ 1741 var alphaCharsAndMarksStr = alphaCharsStr + emojiStr + marksStr; 1742 /** 1743 * The string form of a regular expression that would match all of the 1744 * decimal number chars in the unicode character set when placed in a RegExp 1745 * character class (`[]`). 1746 * 1747 * These would be the characters matched by unicode regex engines `\p{Nd}` 1748 * escape ("all decimal numbers") 1749 * 1750 * Taken from the XRegExp library: http://xregexp.com/ (thanks @https://github.com/slevithan) 1751 * Specifically: http://xregexp.com/v/3.2.0/xregexp-all.js, the 'Decimal_Number' 1752 * regex's bmp 1753 * 1754 * VERY IMPORTANT: This set of characters is defined inside of a Regular 1755 * Expression literal rather than a string literal to prevent UglifyJS from 1756 * compressing the unicode escape sequences into their actual unicode 1757 * characters. If Uglify compresses these into the unicode characters 1758 * themselves, this results in the error "Range out of order in character 1759 * class" when these characters are used inside of a Regular Expression 1760 * character class (`[]`). See usages of this const. Alternatively, we can set 1761 * the UglifyJS option `ascii_only` to true for the build, but that doesn't 1762 * help others who are pulling in Autolinker into their own build and running 1763 * UglifyJS themselves. 1764 */ 1765 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/ 1766 .source; // see note in above variable description 1767 /** 1768 * The string form of a regular expression that would match all of the 1769 * letters and decimal number chars in the unicode character set when placed in 1770 * a RegExp character class (`[]`). 1771 * 1772 * These would be the characters matched by unicode regex engines 1773 * `[\p{L}\p{Nd}]` escape ("all letters and decimal numbers") 1774 */ 1775 var alphaNumericCharsStr = alphaCharsAndMarksStr + decimalNumbersStr; 1776 /** 1777 * The string form of a regular expression that would match all of the 1778 * letters, combining marks, and decimal number chars in the unicode character 1779 * set when placed in a RegExp character class (`[]`). 1780 * 1781 * These would be the characters matched by unicode regex engines 1782 * `[\p{L}\p{M}\p{Nd}]` escape ("all letters, combining marks, and decimal 1783 * numbers") 1784 */
1785 var alphaNumericAndMarksCharsStr = alphaCharsAndMarksStr + decimalNumbersStr; 1786 // Simplified IP regular expression 1787 var ipStr = '(?:[' + decimalNumbersStr + ']{1,3}\\.){3}[' + decimalNumbersStr + ']{1,3}'; 1788 // Protected domain label which do not allow "-" character on the beginning and the end of a single label 1789 var domainLabelStr = '[' + alphaNumericAndMarksCharsStr + '](?:[' + alphaNumericAndMarksCharsStr + '\\-]{0,61}[' + alphaNumericAndMarksCharsStr + '])?'; 1790 var getDomainLabelStr = function (group) { 1791 return '(?=(' + domainLabelStr + '))\\' + group; 1792 }; 1793 /** 1794 * A function to match domain names of a URL or email address. 1795 * Ex: 'google', 'yahoo', 'some-other-company', etc. 1796 */ 1797 var getDomainNameStr = function (group) { 1798 return '(?:' + getDomainLabelStr(group) + '(?:\\.' + getDomainLabelStr(group + 1) + '){0,126}|' + ipStr + ')'; 1799 }; 1800 /** 1801 * A regular expression that is simply the character class of the characters 1802 * that may be used in a domain name, minus the '-' or '.' 1803 */ 1804 var domainNameCharRegex = new RegExp("[" + alphaNumericAndMarksCharsStr + "]"); 1805 1806 // NOTE: THIS IS A GENERATED FILE 1807 // To update with the latest TLD list, run `npm run update-tld-regex` or `yarn update-tld-regex` (depending on which you have installed) 1808
vendor: 11,804 bytes, lines 1808-1810
1808 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|ελ|бг|еÑ|ÑÑ|áá|ë·ë·|ë·ì»´|ì¼ì±|íêµ|ã³ã |ä¸ç|ä¸ä¿¡|ä¸å½|ä¸å|ä¼ä¸|ä½å±±|ä¿¡æ¯|å¥åº·|å «å¦|å ¬å¸|å ¬ç|å°æ¹¾|å°ç£|åå|ååº|åæ |åé|å¨çº¿|大æ¿|娱ä¹|å®¶é»|å·¥è¡|广ä¸|å¾®å|æ å|ææº|æè¡¨|æè|æ¿å¡|æ¿åº|æ°é»|æ¶å°|æ¸ç±|æºæ|游æ|æ¾³é|ç¹ç|ç å®|ç§»å¨|ç½å|ç½åº|ç½ç«|ç½ç»|èé|è°·æ|è´ç©|é販|éå¢|é£å|é¤å |馿¸¯)/; 1809 1810
1810 // For debugging: search for other "For debugging" lines 1811 // import CliTable from 'cli-table'; 1812 // RegExp objects which are shared by all instances of EmailMatcher. These are 1813 // here to avoid re-instantiating the RegExp objects if `Autolinker.link()` is 1814 // called multiple times, thus instantiating EmailMatcher and its RegExp 1815 // objects each time (which is very expensive - see https://github.com/gregjacobs/Autolinker.js/issues/314). 1816 // See descriptions of the properties where they are used for details about them 1817 var localPartCharRegex = new RegExp("[" + alphaNumericAndMarksCharsStr + "!#$%&'*+/=?^_`{|}~-]"); 1818 var strictTldRegex = new RegExp("^" + tldRegex.source + "$"); 1819 /** 1820 * @class Autolinker.matcher.Email 1821 * @extends Autolinker.matcher.Matcher 1822 * 1823 * Matcher to find email matches in an input string. 1824 * 1825 * See this class's superclass ({@link Autolinker.matcher.Matcher}) for more details. 1826 */ 1827 var EmailMatcher = /** @class */ (function (_super) { 1828 __extends(EmailMatcher, _super); 1829 function EmailMatcher() { 1830 var _this = _super !== null && _super.apply(this, arguments) || this; 1831 /** 1832 * Valid characters that can be used in the "local" part of an email address, 1833 * i.e. the "name" part of "[email protected]" 1834 */ 1835 _this.localPartCharRegex = localPartCharRegex; 1836 /** 1837 * Stricter TLD regex which adds a beginning and end check to ensure 1838 * the string is a valid TLD 1839 */ 1840 _this.strictTldRegex = strictTldRegex; 1841 return _this; 1842 } 1843 /** 1844 * @inheritdoc 1845 */ 1846 EmailMatcher.prototype.parseMatches = function (text) { 1847 var tagBuilder = this.tagBuilder, localPartCharRegex = this.localPartCharRegex, strictTldRegex = this.strictTldRegex, matches = [], len = text.length, noCurrentEmailMatch = new CurrentEmailMatch(); 1848 // for matching a 'mailto:' prefix 1849 var mailtoTransitions = { 1850 'm': 'a', 1851 'a': 'i', 1852 'i': 'l', 1853 'l': 't', 1854 't': 'o', 1855 'o': ':', 1856 }; 1857 var charIdx = 0, state = 0 /* NonEmailMatch */, currentEmailMatch = noCurrentEmailMatch; 1858 // For debugging: search for other "For debugging" lines 1859 // const table = new CliTable( { 1860 // head: [ 'charIdx', 'char', 'state', 'charIdx', 'currentEmailAddress.idx', 'hasDomainDot' ] 1861 // } ); 1862 while (charIdx < len) { 1863 var char = text.charAt(charIdx); 1864 // For debugging: search for other "For debugging" lines 1865 // table.push( 1866 // [ charIdx, char, State[ state ], charIdx, currentEmailAddress.idx, currentEmailAddress.hasDomainDot ] 1867 // ); 1868 switch (state) { 1869 case 0 /* NonEmailMatch */: 1870 stateNonEmailAddress(char); 1871 break; 1872 case 1 /* Mailto */: 1873 stateMailTo(text.charAt(charIdx - 1), char); 1874 break; 1875 case 2 /* LocalPart */: 1876 stateLocalPart(char); 1877 break; 1878 case 3 /* LocalPartDot */: 1879 stateLocalPartDot(char); 1880 break; 1881 case 4 /* AtSign */: 1882 stateAtSign(char); 1883 break; 1884 case 5 /* DomainChar */: 1885 stateDomainChar(char); 1886 break; 1887 case 6 /* DomainHyphen */: 1888 stateDomainHyphen(char); 1889 break; 1890 case 7 /* DomainDot */: 1891 stateDomainDot(char); 1892 break; 1893 default: 1894 throwUnhandledCaseError(state); 1895 } 1896 // For debugging: search for other "For debugging" lines 1897 // table.push( 1898 // [ charIdx, char, State[ state ], charIdx, currentEmailAddress.idx, currentEmailAddress.hasDomainDot ] 1899 // ); 1900 charIdx++; 1901 } 1902 // Capture any valid match at the end of the string 1903 captureMatchIfValidAndReset(); 1904 // For debugging: search for other "For debugging" lines 1905 //console.log( '\n' + table.toString() ); 1906 return matches; 1907 // Handles the state when we're not in an email address 1908 function stateNonEmailAddress(char) { 1909 if (char === 'm') { 1910 beginEmailMatch(1 /* Mailto */); 1911 } 1912 else if (localPartCharRegex.test(char)) { 1913 beginEmailMatch(); 1914 } 1915 } 1916 // Handles if we're reading a 'mailto:' prefix on the string 1917 function stateMailTo(prevChar, char) { 1918 if (prevChar === ':') { 1919 // We've reached the end of the 'mailto:' prefix 1920 if (localPartCharRegex.test(char)) { 1921 state = 2 /* LocalPart */; 1922 currentEmailMatch = new CurrentEmailMatch(__assign(__assign({}, currentEmailMatch), { hasMailtoPrefix: true })); 1923 } 1924 else { 1925 // we've matched 'mailto:' but didn't get anything meaningful 1926 // immediately afterwards (for example, we encountered a 1927 // space character, or an '@' character which formed 'mailto:@' 1928 resetToNonEmailMatchState(); 1929 } 1930 } 1931 else if (mailtoTransitions[prevChar] === char) ; 1932 else if (localPartCharRegex.test(char)) { 1933 // We we're reading a prefix of 'mailto:', but encountered a 1934 // different character that didn't continue the prefix 1935 state = 2 /* LocalPart */; 1936 } 1937 else if (char === '.') { 1938 // We we're reading a prefix of 'mailto:', but encountered a 1939 // dot character 1940 state = 3 /* LocalPartDot */; 1941 } 1942 else if (char === '@') { 1943 // We we're reading a prefix of 'mailto:', but encountered a 1944 // an @ character 1945 state = 4 /* AtSign */; 1946 } 1947 else { 1948 // not an email address character, return to "NonEmailAddress" state 1949 resetToNonEmailMatchState(); 1950 } 1951 } 1952 // Handles the state when we're currently in the "local part" of an 1953 // email address (as opposed to the "domain part") 1954 function stateLocalPart(char) { 1955 if (char === '.') { 1956 state = 3 /* LocalPartDot */; 1957 } 1958 else if (char === '@') { 1959 state = 4 /* AtSign */; 1960 } 1961 else if (localPartCharRegex.test(char)) ; 1962 else { 1963 // not an email address character, return to "NonEmailAddress" state 1964 resetToNonEmailMatchState(); 1965 } 1966 } 1967 // Handles the state where we've read 1968 function stateLocalPartDot(char) { 1969 if (char === '.') { 1970 // We read a second '.' in a row, not a valid email address 1971 // local part 1972 resetToNonEmailMatchState(); 1973 } 1974 else if (char === '@') { 1975 // We read the '@' character immediately after a dot ('.'), not 1976 // an email address 1977 resetToNonEmailMatchState(); 1978 } 1979 else if (localPartCharRegex.test(char)) { 1980 state = 2 /* LocalPart */; 1981 } 1982 else { 1983 // Anything else, not an email address 1984 resetToNonEmailMatchState(); 1985 } 1986 } 1987 function stateAtSign(char) { 1988 if (domainNameCharRegex.test(char)) { 1989 state = 5 /* DomainChar */; 1990 } 1991 else { 1992 // Anything else, not an email address 1993 resetToNonEmailMatchState(); 1994 } 1995 } 1996 function stateDomainChar(char) { 1997 if (char === '.') { 1998 state = 7 /* DomainDot */; 1999 } 2000 else if (char === '-') { 2001 state = 6 /* DomainHyphen */; 2002 } 2003 else if (domainNameCharRegex.test(char)) ; 2004 else { 2005 // Anything else, we potentially matched if the criteria has 2006 // been met 2007 captureMatchIfValidAndReset(); 2008 } 2009 } 2010 function stateDomainHyphen(char) { 2011 if (char === '-' || char === '.') {
vendor: 4,766 bytes, lines 2012-2111
2012 // Not valid to have two hyphens ("--") or hypen+dot ("-.") 2013 captureMatchIfValidAndReset(); 2014 } 2015 else if (domainNameCharRegex.test(char)) { 2016 state = 5 /* DomainChar */; 2017 } 2018 else { 2019 // Anything else 2020 captureMatchIfValidAndReset(); 2021 } 2022 } 2023 function stateDomainDot(char) { 2024 if (char === '.' || char === '-') { 2025 // not valid to have two dots ("..") or dot+hypen (".-") 2026 captureMatchIfValidAndReset(); 2027 } 2028 else if (domainNameCharRegex.test(char)) { 2029 state = 5 /* DomainChar */; 2030 // After having read a '.' and then a valid domain character, 2031 // we now know that the domain part of the email is valid, and 2032 // we have found at least a partial EmailMatch (however, the 2033 // email address may have additional characters from this point) 2034 currentEmailMatch = new CurrentEmailMatch(__assign(__assign({}, currentEmailMatch), { hasDomainDot: true })); 2035 } 2036 else { 2037 // Anything else 2038 captureMatchIfValidAndReset(); 2039 } 2040 } 2041 function beginEmailMatch(newState) { 2042 if (newState === void 0) { newState = 2 /* LocalPart */; } 2043 state = newState; 2044 currentEmailMatch = new CurrentEmailMatch({ idx: charIdx }); 2045 } 2046 function resetToNonEmailMatchState() { 2047 state = 0 /* NonEmailMatch */; 2048 currentEmailMatch = noCurrentEmailMatch; 2049 } 2050 /* 2051 * Captures the current email address as an EmailMatch if it's valid, 2052 * and resets the state to read another email address. 2053 */ 2054 function captureMatchIfValidAndReset() { 2055 if (currentEmailMatch.hasDomainDot) { // we need at least one dot in the domain to be considered a valid email address 2056 var matchedText = text.slice(currentEmailMatch.idx, charIdx); 2057 // If we read a '.' or '-' char that ended the email address 2058 // (valid domain name characters, but only valid email address 2059 // characters if they are followed by something else), strip 2060 // it off now 2061 if (/[-.]$/.test(matchedText)) { 2062 matchedText = matchedText.slice(0, -1); 2063 } 2064 var emailAddress = currentEmailMatch.hasMailtoPrefix 2065 ? matchedText.slice('mailto:'.length) 2066 : matchedText; 2067 // if the email address has a valid TLD, add it to the list of matches 2068 if (doesEmailHaveValidTld(emailAddress)) { 2069 matches.push(new EmailMatch({ 2070 tagBuilder: tagBuilder, 2071 matchedText: matchedText, 2072 offset: currentEmailMatch.idx, 2073 email: emailAddress 2074 })); 2075 } 2076 } 2077 resetToNonEmailMatchState(); 2078 /** 2079 * Determines if the given email address has a valid TLD or not 2080 * @param {string} emailAddress - email address 2081 * @return {Boolean} - true is email have valid TLD, false otherwise 2082 */ 2083 function doesEmailHaveValidTld(emailAddress) { 2084 var emailAddressTld = emailAddress.split('.').pop() || ''; 2085 var emailAddressNormalized = emailAddressTld.toLowerCase(); 2086 var isValidTld = strictTldRegex.test(emailAddressNormalized); 2087 return isValidTld; 2088 } 2089 } 2090 }; 2091 return EmailMatcher; 2092 }(Matcher)); 2093 var CurrentEmailMatch = /** @class */ (function () { 2094 function CurrentEmailMatch(cfg) { 2095 if (cfg === void 0) { cfg = {}; } 2096 this.idx = cfg.idx !== undefined ? cfg.idx : -1; 2097 this.hasMailtoPrefix = !!cfg.hasMailtoPrefix; 2098 this.hasDomainDot = !!cfg.hasDomainDot; 2099 } 2100 return CurrentEmailMatch; 2101 }()); 2102 2103 /** 2104 * @private 2105 * @class Autolinker.matcher.UrlMatchValidator 2106 * @singleton 2107 * 2108 * Used by Autolinker to filter out false URL positives from the 2109 * {@link Autolinker.matcher.Url UrlMatcher}. 2110 * 2111 * Due to the limitations of regular expressions (including the missing feature
2112 * of look-behinds in JS regular expressions), we cannot always determine the 2113 * validity of a given match. This class applies a bit of additional logic to 2114 * filter out any false positives that have been matched by the 2115 * {@link Autolinker.matcher.Url UrlMatcher}. 2116 */ 2117 var UrlMatchValidator = /** @class */ (function () { 2118 function UrlMatchValidator() { 2119 } 2120 /** 2121 * Determines if a given URL match found by the {@link Autolinker.matcher.Url UrlMatcher} 2122 * is valid. Will return `false` for: 2123 * 2124 * 1) URL matches which do not have at least have one period ('.') in the 2125 * domain name (effectively skipping over matches like "abc:def"). 2126 * However, URL matches with a protocol will be allowed (ex: 'http://localhost') 2127 * 2) URL matches which do not have at least one word character in the 2128 * domain name (effectively skipping over matches like "git:1.0"). 2129 * However, URL matches with a protocol will be allowed (ex: 'intra-net://271219.76') 2130 * 3) A protocol-relative url match (a URL beginning with '//') whose 2131 * previous character is a word character (effectively skipping over 2132 * strings like "abc//google.com") 2133 * 2134 * Otherwise, returns `true`. 2135 * 2136 * @param {String} urlMatch The matched URL, if there was one. Will be an 2137 * empty string if the match is not a URL match. 2138 * @param {String} protocolUrlMatch The match URL string for a protocol 2139 * match. Ex: 'http://yahoo.com'. This is used to match something like 2140 * 'http://localhost', where we won't double check that the domain name 2141 * has at least one '.' in it. 2142 * @return {Boolean} `true` if the match given is valid and should be
2143 * processed, or `false` if the match is invalid and/or should just not be 2144 * processed. 2145 */ 2146 UrlMatchValidator.isValid = function (urlMatch, protocolUrlMatch) { 2147 if ((protocolUrlMatch && !this.isValidUriScheme(protocolUrlMatch)) || 2148 this.urlMatchDoesNotHaveProtocolOrDot(urlMatch, protocolUrlMatch) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL, *unless* it was a full protocol match (like 'http://localhost') 2149 (this.urlMatchDoesNotHaveAtLeastOneWordChar(urlMatch, protocolUrlMatch) && // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0" 2150 !this.isValidIpAddress(urlMatch)) || // Except if it's an IP address 2151 this.containsMultipleDots(urlMatch)) { 2152 return false; 2153 } 2154 return true; 2155 }; 2156 UrlMatchValidator.isValidIpAddress = function (uriSchemeMatch) { 2157 var newRegex = new RegExp(this.hasFullProtocolRegex.source + this.ipRegex.source); 2158 var uriScheme = uriSchemeMatch.match(newRegex); 2159 return uriScheme !== null; 2160 }; 2161 UrlMatchValidator.containsMultipleDots = function (urlMatch) { 2162 var stringBeforeSlash = urlMatch; 2163 if (this.hasFullProtocolRegex.test(urlMatch)) { 2164 stringBeforeSlash = urlMatch.split('://')[1]; 2165 } 2166 return stringBeforeSlash.split('/')[0].indexOf("..") > -1; 2167 }; 2168 /** 2169 * Determines if the URI scheme is a valid scheme to be autolinked. Returns 2170 * `false` if the scheme is 'javascript:' or 'vbscript:' 2171 * 2172 * @private 2173 * @param {String} uriSchemeMatch The match URL string for a full URI scheme 2174 * match. Ex: 'http://yahoo.com' or 'mailto:[email protected]'. 2175 * @return {Boolean} `true` if the scheme is a valid one, `false` otherwise. 2176 */ 2177 UrlMatchValidator.isValidUriScheme = function (uriSchemeMatch) { 2178 var uriSchemeMatchArr = uriSchemeMatch.match(this.uriSchemeRegex), uriScheme = uriSchemeMatchArr && uriSchemeMatchArr[0].toLowerCase(); 2179 return (uriScheme !== 'javascript:' && uriScheme !== 'vbscript:'); 2180 }; 2181 /** 2182 * Determines if a URL match does not have either: 2183 * 2184 * a) a full protocol (i.e. 'http://'), or 2185 * b) at least one dot ('.') in the domain name (for a non-full-protocol 2186 * match). 2187 * 2188 * Either situation is considered an invalid URL (ex: 'git:d' does not have 2189 * either the '://' part, or at least one dot in the domain name. If the 2190 * match was 'git:abc.com', we would consider this valid.) 2191 * 2192 * @private 2193 * @param {String} urlMatch The matched URL, if there was one. Will be an 2194 * empty string if the match is not a URL match. 2195 * @param {String} protocolUrlMatch The match URL string for a protocol 2196 * match. Ex: 'http://yahoo.com'. This is used to match something like 2197 * 'http://localhost', where we won't double check that the domain name 2198 * has at least one '.' in it. 2199 * @return {Boolean} `true` if the URL match does not have a full protocol, 2200 * or at least one dot ('.') in a non-full-protocol match. 2201 */ 2202 UrlMatchValidator.urlMatchDoesNotHaveProtocolOrDot = function (urlMatch, protocolUrlMatch) { 2203 return (!!urlMatch && (!protocolUrlMatch || !this.hasFullProtocolRegex.test(protocolUrlMatch)) && urlMatch.indexOf('.') === -1); 2204 }; 2205 /** 2206 * Determines if a URL match does not have either: 2207 * 2208 * a) a full protocol (i.e. 'http://'), or 2209 * b) at least one word character after the protocol (i.e. in the domain name) 2210 * 2211 * At least one letter character must exist in the domain name after a 2212 * protocol match. Ex: skip over something like "git:1.0" 2213 * 2214 * @private 2215 * @param {String} urlMatch The matched URL, if there was one. Will be an 2216 * empty string if the match is not a URL match. 2217 * @param {String} protocolUrlMatch The match URL string for a protocol 2218 * match. Ex: 'http://yahoo.com'. This is used to know whether or not we 2219 * have a protocol in the URL string, in order to check for a word 2220 * character after the protocol separator (':'). 2221 * @return {Boolean} `true` if the URL match does not have a full protocol, or 2222 * at least one word character in it, `false` otherwise. 2223 */ 2224 UrlMatchValidator.urlMatchDoesNotHaveAtLeastOneWordChar = function (urlMatch, protocolUrlMatch) { 2225 if (urlMatch && protocolUrlMatch) { 2226 return !this.hasFullProtocolRegex.test(protocolUrlMatch) && !this.hasWordCharAfterProtocolRegex.test(urlMatch); 2227 } 2228 else { 2229 return false;
2230 } 2231 }; 2232 /** 2233 * Regex to test for a full protocol, with the two trailing slashes. Ex: 'http://' 2234 * 2235 * @private 2236 * @property {RegExp} hasFullProtocolRegex 2237 */ 2238 UrlMatchValidator.hasFullProtocolRegex = /^[A-Za-z][-.+A-Za-z0-9]*:\/\//; 2239 /** 2240 * Regex to find the URI scheme, such as 'mailto:'. 2241 * 2242 * This is used to filter out 'javascript:' and 'vbscript:' schemes. 2243 * 2244 * @private 2245 * @property {RegExp} uriSchemeRegex 2246 */ 2247 UrlMatchValidator.uriSchemeRegex = /^[A-Za-z][-.+A-Za-z0-9]*:/; 2248 /** 2249 * Regex to determine if at least one word char exists after the protocol (i.e. after the ':') 2250 * 2251 * @private 2252 * @property {RegExp} hasWordCharAfterProtocolRegex 2253 */ 2254 UrlMatchValidator.hasWordCharAfterProtocolRegex = new RegExp(":[^\\s]*?[" + alphaCharsStr + "]"); 2255 /** 2256 * Regex to determine if the string is a valid IP address 2257 * 2258 * @private 2259 * @property {RegExp} ipRegex 2260 */ 2261 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]*)?\/?$/; 2262 return UrlMatchValidator; 2263 }()); 2264 2265 // RegExp objects which are shared by all instances of UrlMatcher. These are 2266 // here to avoid re-instantiating the RegExp objects if `Autolinker.link()` is 2267 // called multiple times, thus instantiating UrlMatcher and its RegExp 2268 // objects each time (which is very expensive - see https://github.com/gregjacobs/Autolinker.js/issues/314). 2269 // See descriptions of the properties where they are used for details about them 2270 var matcherRegex = (function () { 2271 var schemeRegex = /(?:[A-Za-z][-.+A-Za-z0-9]{0,63}:(?![A-Za-z][-.+A-Za-z0-9]{0,63}:\/\/)(?!\d+\/?)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:"). Also, make sure we don't interpret 'google.com:8000' as if 'google.com' was a protocol here (i.e. ignore a trailing port number in this regex) 2272 wwwRegex = /(?:www\.)/, // starting with 'www.' 2273 // Allow optional path, query string, and hash anchor, not ending in the following characters: "?!:,.;" 2274 // http://blog.codinghorror.com/the-problem-with-urls/ 2275 urlSuffixRegex = new RegExp('[/?#](?:[' + alphaNumericAndMarksCharsStr + '\\-+&@#/%=~_()|\'$*\\[\\]{}?!:,.;^\u2713]*[' + alphaNumericAndMarksCharsStr + '\\-+&@#/%=~_()|\'$*\\[\\]{}\u2713])?'); 2276 return new RegExp([ 2277 '(?:', 2278 '(', 2279 schemeRegex.source, 2280 getDomainNameStr(2), 2281 ')', 2282 '|', 2283 '(', 2284 '(//)?', 2285 wwwRegex.source, 2286 getDomainNameStr(6), 2287 ')', 2288 '|', 2289 '(', 2290 '(//)?', 2291 getDomainNameStr(10) + '\\.', 2292 tldRegex.source, 2293 '(?![-' + alphaNumericCharsStr + '])', 2294 ')', 2295 ')', 2296 '(?::[0-9]+)?', 2297 '(?:' + urlSuffixRegex.source + ')?' // match for path, query string, and/or hash anchor - optional 2298 ].join(""), 'gi'); 2299 })(); 2300 var wordCharRegExp = new RegExp('[' + alphaNumericAndMarksCharsStr + ']'); 2301 /** 2302 * @class Autolinker.matcher.Url 2303 * @extends Autolinker.matcher.Matcher 2304 * 2305 * Matcher to find URL matches in an input string. 2306 * 2307 * See this class's superclass ({@link Autolinker.matcher.Matcher}) for more details. 2308 */ 2309 var UrlMatcher = /** @class */ (function (_super) { 2310 __extends(UrlMatcher, _super); 2311 /** 2312 * @method constructor 2313 * @param {Object} cfg The configuration properties for the Match instance, 2314 * specified in an Object (map). 2315 */ 2316 function UrlMatcher(cfg) { 2317 var _this = _super.call(this, cfg) || this; 2318 /** 2319 * @cfg {Object} stripPrefix (required) 2320 *
2321 * The Object form of {@link Autolinker#cfg-stripPrefix}. 2322 */ 2323 _this.stripPrefix = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator 2324 /** 2325 * @cfg {Boolean} stripTrailingSlash (required) 2326 * @inheritdoc Autolinker#stripTrailingSlash 2327 */ 2328 _this.stripTrailingSlash = true; // default value just to get the above doc comment in the ES5 output and documentation generator 2329 /** 2330 * @cfg {Boolean} decodePercentEncoding (required) 2331 * @inheritdoc Autolinker#decodePercentEncoding 2332 */ 2333 _this.decodePercentEncoding = true; // default value just to get the above doc comment in the ES5 output and documentation generator 2334 /** 2335 * @protected 2336 * @property {RegExp} matcherRegex 2337 * 2338 * The regular expression to match URLs with an optional scheme, port 2339 * number, path, query string, and hash anchor. 2340 * 2341 * Example matches: 2342 * 2343 * http://google.com 2344 * www.google.com 2345 * google.com/path/to/file?q1=1&q2=2#myAnchor 2346 * 2347 * 2348 * This regular expression will have the following capturing groups: 2349 * 2350 * 1. Group that matches a scheme-prefixed URL (i.e. 'http://google.com'). 2351 * This is used to match scheme URLs with just a single word, such as 2352 * 'http://localhost', where we won't double check that the domain name 2353 * has at least one dot ('.') in it. 2354 * 2. Group that matches a 'www.' prefixed URL. This is only matched if the 2355 * 'www.' text was not prefixed by a scheme (i.e.: not prefixed by 2356 * 'http://', 'ftp:', etc.) 2357 * 3. A protocol-relative ('//') match for the case of a 'www.' prefixed 2358 * URL. Will be an empty string if it is not a protocol-relative match. 2359 * We need to know the character before the '//' in order to determine
2360 * if it is a valid match or the // was in a string we don't want to 2361 * auto-link. 2362 * 4. Group that matches a known TLD (top level domain), when a scheme 2363 * or 'www.'-prefixed domain is not matched. 2364 * 5. A protocol-relative ('//') match for the case of a known TLD prefixed 2365 * URL. Will be an empty string if it is not a protocol-relative match. 2366 * See #3 for more info. 2367 */ 2368 _this.matcherRegex = matcherRegex; 2369 /** 2370 * A regular expression to use to check the character before a protocol-relative 2371 * URL match. We don't want to match a protocol-relative URL if it is part 2372 * of another word. 2373 * 2374 * For example, we want to match something like "Go to: //google.com", 2375 * but we don't want to match something like "abc//google.com" 2376 * 2377 * This regular expression is used to test the character before the '//'. 2378 * 2379 * @protected 2380 * @type {RegExp} wordCharRegExp 2381 */ 2382 _this.wordCharRegExp = wordCharRegExp; 2383 _this.stripPrefix = cfg.stripPrefix; 2384 _this.stripTrailingSlash = cfg.stripTrailingSlash; 2385 _this.decodePercentEncoding = cfg.decodePercentEncoding; 2386 return _this; 2387 } 2388 /** 2389 * @inheritdoc 2390 */ 2391 UrlMatcher.prototype.parseMatches = function (text) { 2392 var matcherRegex = this.matcherRegex, stripPrefix = this.stripPrefix, stripTrailingSlash = this.stripTrailingSlash, decodePercentEncoding = this.decodePercentEncoding, tagBuilder = this.tagBuilder, matches = [], match; 2393 var _loop_1 = function () { 2394 var matchStr = match[0], schemeUrlMatch = match[1], wwwUrlMatch = match[4], wwwProtocolRelativeMatch = match[5], 2395 //tldUrlMatch = match[ 8 ], -- not needed at the moment 2396 tldProtocolRelativeMatch = match[9], offset = match.index, protocolRelativeMatch = wwwProtocolRelativeMatch || tldProtocolRelativeMatch, prevChar = text.charAt(offset - 1); 2397 if (!UrlMatchValidator.isValid(matchStr, schemeUrlMatch)) { 2398 return "continue"; 2399 } 2400 // If the match is preceded by an '@' character, then it is either 2401 // an email address or a username. Skip these types of matches. 2402 if (offset > 0 && prevChar === '@') { 2403 return "continue"; 2404 } 2405 // If it's a protocol-relative '//' match, but the character before the '//' 2406 // was a word character (i.e. a letter/number), then we found the '//' in the 2407 // middle of another word (such as "asdf//asdf.com"). In this case, skip the 2408 // match. 2409 if (offset > 0 && protocolRelativeMatch && this_1.wordCharRegExp.test(prevChar)) { 2410 return "continue"; 2411 } 2412 // If the URL ends with a question mark, don't include the question 2413 // mark as part of the URL. We'll assume the question mark was the 2414 // end of a sentence, such as: "Going to google.com?" 2415 if (/\?$/.test(matchStr)) { 2416 matchStr = matchStr.substr(0, matchStr.length - 1); 2417 } 2418 // Handle a closing parenthesis or square bracket at the end of the 2419 // match, and exclude it if there is not a matching open parenthesis 2420 // or square bracket in the match itself. 2421 if (this_1.matchHasUnbalancedClosingParen(matchStr)) { 2422 matchStr = matchStr.substr(0, matchStr.length - 1); // remove the trailing ")" 2423 } 2424 else { 2425 // Handle an invalid character after the TLD 2426 var pos = this_1.matchHasInvalidCharAfterTld(matchStr, schemeUrlMatch); 2427 if (pos > -1) { 2428 matchStr = matchStr.substr(0, pos); // remove the trailing invalid chars 2429 } 2430 } 2431 // The autolinker accepts many characters in a url's scheme (like `fake://test.com`). 2432 // However, in cases where a URL is missing whitespace before an obvious link, 2433 // (for example: `nowhitespacehttp://www.test.com`), we only want the match to start 2434 // at the http:// part. We will check if the match contains a common scheme and then 2435 // shift the match to start from there. 2436 var foundCommonScheme = ['http://', 'https://'].find(function (commonScheme) { return !!schemeUrlMatch && schemeUrlMatch.indexOf(commonScheme) !== -1; }); 2437 if (foundCommonScheme) { 2438 // If we found an overmatched URL, we want to find the index 2439 // of where the match should start and shift the match to 2440 // start from the beginning of the common scheme 2441 var indexOfSchemeStart = matchStr.indexOf(foundCommonScheme); 2442 matchStr = matchStr.substr(indexOfSchemeStart); 2443 schemeUrlMatch = schemeUrlMatch.substr(indexOfSchemeStart); 2444 offset = offset + indexOfSchemeStart; 2445 } 2446 var urlMatchType = schemeUrlMatch ? 'scheme' : (wwwUrlMatch ? 'www' : 'tld'), protocolUrlMatch = !!schemeUrlMatch; 2447 matches.push(new UrlMatch({ 2448 tagBuilder: tagBuilder, 2449 matchedText: matchStr, 2450 offset: offset, 2451 urlMatchType: urlMatchType, 2452 url: matchStr, 2453 protocolUrlMatch: protocolUrlMatch, 2454 protocolRelativeMatch: !!protocolRelativeMatch,
vendor: 4,690 bytes, lines 2455-2554
2455 stripPrefix: stripPrefix, 2456 stripTrailingSlash: stripTrailingSlash, 2457 decodePercentEncoding: decodePercentEncoding, 2458 })); 2459 }; 2460 var this_1 = this; 2461 while ((match = matcherRegex.exec(text)) !== null) { 2462 _loop_1(); 2463 } 2464 return matches; 2465 }; 2466 /** 2467 * Determines if a match found has an unmatched closing parenthesis, 2468 * square bracket or curly bracket. If so, the symbol will be removed 2469 * from the match itself, and appended after the generated anchor tag. 2470 * 2471 * A match may have an extra closing parenthesis at the end of the match 2472 * because the regular expression must include parenthesis for URLs such as 2473 * "wikipedia.com/something_(disambiguation)", which should be auto-linked. 2474 * 2475 * However, an extra parenthesis *will* be included when the URL itself is 2476 * wrapped in parenthesis, such as in the case of: 2477 * "(wikipedia.com/something_(disambiguation))" 2478 * In this case, the last closing parenthesis should *not* be part of the 2479 * URL itself, and this method will return `true`. 2480 * 2481 * For square brackets in URLs such as in PHP arrays, the same behavior as 2482 * parenthesis discussed above should happen: 2483 * "[http://www.example.com/foo.php?bar[]=1&bar[]=2&bar[]=3]" 2484 * The closing square bracket should not be part of the URL itself, and this 2485 * method will return `true`. 2486 * 2487 * @protected 2488 * @param {String} matchStr The full match string from the {@link #matcherRegex}. 2489 * @return {Boolean} `true` if there is an unbalanced closing parenthesis or 2490 * square bracket at the end of the `matchStr`, `false` otherwise. 2491 */ 2492 UrlMatcher.prototype.matchHasUnbalancedClosingParen = function (matchStr) { 2493 var endChar = matchStr.charAt(matchStr.length - 1); 2494 var startChar; 2495 if (endChar === ')') { 2496 startChar = '('; 2497 } 2498 else if (endChar === ']') { 2499 startChar = '['; 2500 } 2501 else if (endChar === '}') { 2502 startChar = '{'; 2503 } 2504 else { 2505 return false; // not a close parenthesis or square bracket 2506 } 2507 // Find if there are the same number of open braces as close braces in 2508 // the URL string, minus the last character (which we have already 2509 // determined to be either ')', ']' or '}' 2510 var numOpenBraces = 0; 2511 for (var i = 0, len = matchStr.length - 1; i < len; i++) { 2512 var char = matchStr.charAt(i); 2513 if (char === startChar) { 2514 numOpenBraces++; 2515 } 2516 else if (char === endChar) { 2517 numOpenBraces = Math.max(numOpenBraces - 1, 0); 2518 } 2519 } 2520 // If the number of open braces matches the number of close braces in 2521 // the URL minus the last character, then the match has *unbalanced* 2522 // braces because of the last character. Example of unbalanced braces 2523 // from the regex match: 2524 // "http://example.com?a[]=1]" 2525 if (numOpenBraces === 0) { 2526 return true; 2527 } 2528 return false; 2529 }; 2530 /** 2531 * Determine if there's an invalid character after the TLD in a URL. Valid 2532 * characters after TLD are ':/?#'. Exclude scheme matched URLs from this 2533 * check. 2534 * 2535 * @protected 2536 * @param {String} urlMatch The matched URL, if there was one. Will be an 2537 * empty string if the match is not a URL match. 2538 * @param {String} schemeUrlMatch The match URL string for a scheme 2539 * match. Ex: 'http://yahoo.com'. This is used to match something like 2540 * 'http://localhost', where we won't double check that the domain name 2541 * has at least one '.' in it. 2542 * @return {Number} the position where the invalid character was found. If 2543 * no such character was found, returns -1 2544 */ 2545 UrlMatcher.prototype.matchHasInvalidCharAfterTld = function (urlMatch, schemeUrlMatch) { 2546 if (!urlMatch) { 2547 return -1; 2548 } 2549 var offset = 0; 2550 if (schemeUrlMatch) { 2551 offset = urlMatch.indexOf(':'); 2552 urlMatch = urlMatch.slice(offset); 2553 } 2554 var re = new RegExp("^((.?\/\/)?[-." + alphaNumericAn
2554dMarksCharsStr + "]*[-" + alphaNumericAndMarksCharsStr + "]\\.[-" + alphaNumericAndMarksCharsStr + "]+)"); 2555 var res = re.exec(urlMatch); 2556 if (res === null) { 2557 return -1; 2558 } 2559 offset += res[1].length; 2560 urlMatch = urlMatch.slice(res[1].length); 2561 if (/^[^-.A-Za-z0-9:\/?#]/.test(urlMatch)) { 2562 return offset; 2563 } 2564 return -1; 2565 }; 2566 return UrlMatcher; 2567 }(Matcher)); 2568 2569 // RegExp objects which are shared by all instances of HashtagMatcher. These are 2570 // here to avoid re-instantiating the RegExp objects if `Autolinker.link()` is 2571 // called multiple times, thus instantiating HashtagMatcher and its RegExp 2572 // objects each time (which is very expensive - see https://github.com/gregjacobs/Autolinker.js/issues/314). 2573 // See descriptions of the properties where they are used for details about them 2574 var matcherRegex$1 = new RegExp("#[_" + alphaNumericAndMarksCharsStr + "]{1,139}(?![_" + alphaNumericAndMarksCharsStr + "])", 'g'); // lookahead used to make sure we don't match something above 139 characters 2575 var nonWordCharRegex = new RegExp('[^' + alphaNumericAndMarksCharsStr + ']'); 2576 /** 2577 * @class Autolinker.matcher.Hashtag 2578 * @extends Autolinker.matcher.Matcher 2579 * 2580 * Matcher to find HashtagMatch matches in an input string. 2581 */ 2582 var HashtagMatcher = /** @class */ (function (_super) { 2583 __extends(HashtagMatcher, _super); 2584 /** 2585 * @method constructor 2586 * @param {Object} cfg The configuration properties for the Match instance, 2587 * specified in an Object (map). 2588 */ 2589 function HashtagMatcher(cfg) { 2590 var _this = _super.call(this, cfg) || this; 2591 /** 2592 * @cfg {String} serviceName 2593 * 2594 * The service to point hashtag matches to. See {@link Autolinker#hashtag} 2595 * for available values. 2596 */ 2597 _this.serviceName = 'twitter'; // default value just to get the above doc comment in the ES5 output and documentation generator 2598 /** 2599 * The regular expression to match Hashtags. Example match: 2600 * 2601 * #asdf 2602 * 2603 * @protected 2604 * @property {RegExp} matcherRegex 2605 */ 2606 _this.matcherRegex = matcherRegex$1; 2607 /** 2608 * The regular expression to use to check the character before a username match to 2609 * make sure we didn't accidentally match an email address. 2610 * 2611 * For example, the string "[email protected]" should not match "@asdf" as a username. 2612 * 2613 * @protected 2614 * @property {RegExp} nonWordCharRegex 2615 */ 2616 _this.nonWordCharRegex = nonWordCharRegex; 2617 _this.serviceName = cfg.serviceName; 2618 return _this; 2619 } 2620 /** 2621 * @inheritdoc 2622 */ 2623 HashtagMatcher.prototype.parseMatches = function (text) { 2624 var matcherRegex = this.matcherRegex, nonWordCharRegex = this.nonWordCharRegex, serviceName = this.serviceName, tagBuilder = this.tagBuilder, matches = [], match; 2625 while ((match = matcherRegex.exec(text)) !== null) { 2626 var offset = match.index, prevChar = text.charAt(offset - 1); 2627 // If we found the match at the beginning of the string, or we found the match 2628 // and there is a whitespace char in front of it (meaning it is not a '#' char 2629 // in the middle of a word), then it is a hashtag match. 2630 if (offset === 0 || nonWordCharRegex.test(prevChar)) { 2631 var matchedText = match[0], hashtag = match[0].slice(1); // strip off the '#' character at the beginning 2632 matches.push(new HashtagMatch({ 2633 tagBuilder: tagBuilder, 2634 matchedText: matchedText, 2635 offset: offset, 2636 serviceName: serviceName, 2637 hashtag: hashtag 2638 })); 2639 } 2640 } 2641 return matches; 2642 }; 2643 return HashtagMatcher; 2644 }(Matcher)); 2645 2646 // RegExp objects which are shared by all instances of PhoneMatcher. These are 2647 // here to avoid re-instantiating the RegExp objects if `Autolinker.link()` is 2648 // called multiple times, thus instantiating PhoneMatcher and its RegExp 2649 // objects each time (which is very expensive - see https://github.com/gregjacobs/Autolinker.js/issues/314). 2650 // See descriptions of the properties where they are used for details about them 2651 // Over the years, many people have added to this regex, but it should have been 2652 // split up by country. Maybe one day we can break this down. 2653 var mostPhoneNumbers = /(?:(?:(?:(\+)?\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]+#?)*/; 2654 // Regex for Japanese phone numbers 2655 var japanesePhoneRe = /(0([1-9]{1}-?[1-9]\d{3}|[1-9]{2}-?\d{3}|[1-9]{2}\d{1}-?\d{2}|[1-9]{2}\d{2}-?\d{1})-?\d{4}|0[789]0-?\d{4}-?\d{4}|050-?\d{4}-?\d{4})/; 2656 // Combined regex 2657 var phoneMatcherRegex = new RegExp(mostPhoneNumbers.source + "|" + japanesePhoneRe.source, 'g'); 2658 /** 2659 * @class Autolinker.matcher.Phone 2660 * @extends Autolinker.matcher.Matcher 2661 * 2662 * Matcher to find Phone number matches in an input string. 2663 * 2664 * See this class's superclass ({@link Autolinker.matcher.Matcher}) for more 2665 * details. 2666 */ 2667 var PhoneMatcher = /** @class */ (function (_super) { 2668 __extends(PhoneMatcher, _super); 2669 function PhoneMatcher() { 2670 var _this = _super !== null && _super.apply(this, arguments) || this; 2671 /** 2672 * The regular expression to match Phone numbers. Example matches: 2673 * 2674 * (123) 456-7890 2675 * 123 456 7890 2676 * 123-456-7890 2677 * +18004441234,,;,10226420346# 2678 * +1 (800) 444 1234 2679 * 10226420346# 2680 * 1-800-444-1234,1022,64,20346# 2681 * 2682 * This regular expression has the following capturing groups: 2683 * 2684 * 1 or 2. The prefixed '+' sign, if there is one. 2685 * 2686 * @protected 2687 * @property {RegExp} matcherRegex 2688 */ 2689 _this.matcherRegex = phoneMatcherRegex; 2690 return _this; 2691 } 2692 /** 2693 * @inheritdoc 2694 */ 2695 PhoneMatcher.prototype.parseMatches = function (text) { 2696 var matcherRegex = this.matcherRegex, tagBuilder = this.tagBuilder, matches = [], match; 2697 while ((match = matcherRegex.exec(text)) !== null) { 2698 // Remove non-numeric values from phone number string 2699 var matchedText = match[0], cleanNumber = matchedText.replace(/[^0-9,;#]/g, ''), // strip out non-digit characters exclude comma semicolon and # 2700 plusSign = !!(match[1] || match[2]), // match[ 1 ] or match[ 2 ] is the prefixed plus sign, if there is one 2701 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/); 2702 if (this.testMatch(match[3]) && this.testMatch(matchedText) && contextClear) { 2703 matches.push(new PhoneMatch({ 2704 tagBuilder: tagBuilder, 2705 matchedText: matchedText, 2706 offset: match.index, 2707 number: cleanNumber, 2708 plusSign: plusSign 2709 })); 2710 } 2711 } 2712 return matches; 2713 }; 2714 PhoneMatcher.prototype.testMatch = function (text) { 2715 return nonDigitRe.test(text); 2716 }; 2717 return PhoneMatcher; 2718 }(Matcher)); 2719 2720 // RegExp objects which are shared by all instances of MentionMatcher. These are 2721 // here to avoid re-instantiating the RegExp objects if `Autolinker.link()` is 2722 // called multiple times, thus instantiating MentionMatcher and its RegExp 2723 // objects each time (which is very expensive - see https://github.com/gregjacobs/Autolinker.js/issues/314). 2724 // See descriptions of the properties where they are used for details about them
2725 var twitterRegex = new RegExp("@[_" + alphaNumericAndMarksCharsStr + "]{1,50}(?![_" + alphaNumericAndMarksCharsStr + "])", 'g'); // lookahead used to make sure we don't match something above 50 characters 2726 var instagramRegex = new RegExp("@[_." + alphaNumericAndMarksCharsStr + "]{1,30}(?![_" + alphaNumericAndMarksCharsStr + "])", 'g'); // lookahead used to make sure we don't match something above 30 characters 2727 var soundcloudRegex = new RegExp("@[-_." + alphaNumericAndMarksCharsStr + "]{1,50}(?![-_" + alphaNumericAndMarksCharsStr + "])", 'g'); // lookahead used to make sure we don't match something above 50 characters 2728 var nonWordCharRegex$1 = new RegExp('[^' + alphaNumericAndMarksCharsStr + ']'); 2729 /** 2730 * @class Autolinker.matcher.Mention 2731 * @extends Autolinker.matcher.Matcher 2732 * 2733 * Matcher to find/replace username matches in an input string. 2734 */ 2735 var MentionMatcher = /** @class */ (function (_super) { 2736 __extends(MentionMatcher, _super); 2737 /** 2738 * @method constructor 2739 * @param {Object} cfg The configuration properties for the Match instance, 2740 * specified in an Object (map). 2741 */ 2742 function MentionMatcher(cfg) { 2743 var _this = _super.call(this, cfg) || this; 2744 /** 2745 * @cfg {'twitter'/'instagram'/'soundcloud'} protected 2746 * 2747 * The name of service to link @mentions to. 2748 * 2749 * Valid values are: 'twitter', 'instagram', or 'soundcloud' 2750 */ 2751 _this.serviceName = 'twitter'; // default value just to get the above doc comment in the ES5 output and documentation generator 2752 /** 2753 * Hash of regular expression to match username handles. Example match: 2754 * 2755 * @asdf 2756 * 2757 * @private 2758 * @property {Object} matcherRegexes 2759 */ 2760 _this.matcherRegexes = { 2761 'twitter': twitterRegex, 2762 'instagram': instagramRegex, 2763 'soundcloud': soundcloudRegex 2764 }; 2765 /** 2766 * The regular expression to use to check the character before a username match to 2767 * make sure we didn't accidentally match an email address. 2768 * 2769 * For example, the string "[email protected]" should not match "@asdf" as a username. 2770 * 2771 * @private 2772 * @property {RegExp} nonWordCharRegex 2773 */ 2774 _this.nonWordCharRegex = nonWordCharRegex$1; 2775 _this.serviceName = cfg.serviceName; 2776 return _this; 2777 } 2778 /** 2779 * @inheritdoc 2780 */ 2781 MentionMatcher.prototype.parseMatches = function (text) { 2782 var serviceName = this.serviceName, matcherRegex = this.matcherRegexes[this.serviceName], nonWordCharRegex = this.nonWordCharRegex, tagBuilder = this.tagBuilder, matches = [], match; 2783 if (!matcherRegex) { 2784 return matches; 2785 } 2786 while ((match = matcherRegex.exec(text)) !== null) { 2787 var offset = match.index, prevChar = text.charAt(offset - 1); 2788 // If we found the match at the beginning of the string, or we found the match 2789 // and there is a whitespace char in front of it (meaning it is not an email 2790 // address), then it is a username match. 2791 if (offset === 0 || nonWordCharRegex.test(prevChar)) { 2792 var matchedText = match[0].replace(/\.+$/g, ''), // strip off trailing . 2793 mention = matchedText.slice(1); // strip off the '@' character at the beginning 2794 matches.push(new MentionMatch({ 2795 tagBuilder: tagBuilder, 2796 matchedText: matchedText, 2797 offset: offset, 2798 serviceName: serviceName, 2799 mention: mention 2800 })); 2801 } 2802 } 2803 return matches; 2804 }; 2805 return MentionMatcher; 2806 }(Matcher)); 2807 2808 // For debugging: search for other "For debugging" lines 2809 // import CliTable from 'cli-table'; 2810 /** 2811 * Parses an HTML string, calling the callbacks to notify of tags and text. 2812 * 2813 * ## History 2814 * 2815 * This file previously used a regular expression to find html tags in the input
2816 * text. Unfortunately, we ran into a bunch of catastrophic backtracking issues 2817 * with certain input text, causing Autolinker to either hang or just take a 2818 * really long time to parse the string. 2819 * 2820 * The current code is intended to be a O(n) algorithm that walks through 2821 * the string in one pass, and tries to be as cheap as possible. We don't need 2822 * to implement the full HTML spec, but rather simply determine where the string 2823 * looks like an HTML tag, and where it looks like text (so that we can autolink 2824 * that). 2825 * 2826 * This state machine parser is intended just to be a simple but performant 2827 * parser of HTML for the subset of requirements we have. We simply need to: 2828 * 2829 * 1. Determine where HTML tags are 2830 * 2. Determine the tag name (Autolinker specifically only cares about <a>, 2831 * <script>, and <style> tags, so as not to link any text within them) 2832 * 2833 * We don't need to: 2834 * 2835 * 1. Create a parse tree 2836 * 2. Auto-close tags with invalid markup 2837 * 3. etc. 2838 * 2839 * The other intention behind this is that we didn't want to add external 2840 * dependencies on the Autolinker utility which would increase its size. For 2841 * instance, adding htmlparser2 adds 125kb to the minified output file, 2842 * increasing its final size from 47kb to 172kb (at the time of writing). It 2843 * also doesn't work exactly correctly, treating the string "<3 blah blah blah" 2844 * as an HTML tag. 2845 * 2846 * Reference for HTML spec: 2847 * 2848 * https://www.w3.org/TR/html51/syntax.html#sec-tokenization 2849 * 2850 * @param {String} html The HTML to parse 2851 * @param {Object} callbacks 2852 * @param {Function} callbacks.onOpenTag Callback function to call when an open 2853 * tag is parsed. Called with the tagName as its argument. 2854 * @param {Function} callbacks.onCloseTag Callback function to call when a close 2855 * tag is parsed. Called with the tagName as its argument. If a self-closing 2856 * tag is found, `onCloseTag` is called immediately after `onOpenTag`. 2857 * @param {Function} callbacks.onText Callback function to call when text (i.e 2858 * not an HTML tag) is parsed. Called with the text (string) as its first 2859 * argument, and offset (number) into the string as its second. 2860 */ 2861 function parseHtml(html, _a) { 2862 var onOpenTag = _a.onOpenTag, onCloseTag = _a.onCloseTag, onText = _a.onText, onComment = _a.onComment, onDoctype = _a.onDoctype; 2863 var noCurrentTag = new CurrentTag(); 2864 var charIdx = 0, len = html.length, state = 0 /* Data */, currentDataIdx = 0, // where the current data start index is 2865 currentTag = noCurrentTag; // describes the current tag that is being read 2866 // For debugging: search for other "For debugging" lines 2867 // const table = new CliTable( { 2868 // head: [ 'charIdx', 'char', 'state', 'currentDataIdx', 'currentOpenTagIdx', 'tag.type' ] 2869 // } ); 2870 while (charIdx < len) { 2871 var char = html.charAt(charIdx); 2872 // For debugging: search for other "For debugging" lines 2873 // ALSO: Temporarily remove the 'const' keyword on the State enum 2874 // table.push( 2875 // [ charIdx, char, State[ state ], currentDataIdx, currentTag.idx, currentTag.idx === -1 ? '' : currentTag.type ] 2876 // ); 2877 switch (state) { 2878 case 0 /* Data */:
2879 stateData(char); 2880 break; 2881 case 1 /* TagOpen */: 2882 stateTagOpen(char); 2883 break; 2884 case 2 /* EndTagOpen */: 2885 stateEndTagOpen(char); 2886 break; 2887 case 3 /* TagName */: 2888 stateTagName(char); 2889 break; 2890 case 4 /* BeforeAttributeName */: 2891 stateBeforeAttributeName(char); 2892 break; 2893 case 5 /* AttributeName */: 2894 stateAttributeName(char); 2895 break; 2896 case 6 /* AfterAttributeName */: 2897 stateAfterAttributeName(char); 2898 break; 2899 case 7 /* BeforeAttributeValue */: 2900 stateBeforeAttributeValue(char); 2901 break; 2902 case 8 /* AttributeValueDoubleQuoted */: 2903 stateAttributeValueDoubleQuoted(char); 2904 break; 2905 case 9 /* AttributeValueSingleQuoted */: 2906 stateAttributeValueSingleQuoted(char); 2907 break; 2908 case 10 /* AttributeValueUnquoted */: 2909 stateAttributeValueUnquoted(char); 2910 break; 2911 case 11 /* AfterAttributeValueQuoted */: 2912 stateAfterAttributeValueQuoted(char); 2913 break; 2914 case 12 /* SelfClosingStartTag */: 2915 stateSelfClosingStartTag(char); 2916 break; 2917 case 13 /* MarkupDeclarationOpenState */: 2918 stateMarkupDeclarationOpen(char); 2919 break; 2920 case 14 /* CommentStart */: 2921 stateCommentStart(char); 2922 break; 2923 case 15 /* CommentStartDash */: 2924 stateCommentStartDash(char); 2925 break; 2926 case 16 /* Comment */: 2927 stateComment(char); 2928 break; 2929 case 17 /* CommentEndDash */: 2930 stateCommentEndDash(char); 2931 break; 2932 case 18 /* CommentEnd */: 2933 stateCommentEnd(char); 2934 break; 2935 case 19 /* CommentEndBang */: 2936 stateCommentEndBang(char); 2937 break; 2938 case 20 /* Doctype */: 2939 stateDoctype(char); 2940 break; 2941 default: 2942 throwUnhandledCaseError(state); 2943 } 2944 // For debugging: search for other "For debugging" lines 2945 // ALSO: Temporarily remove the 'const' keyword on the State enum 2946 // table.push( 2947 // [ charIdx, char, State[ state ], currentDataIdx, currentTag.idx, currentTag.idx === -1 ? '' : currentTag.type ] 2948 // ); 2949 charIdx++; 2950 } 2951 if (currentDataIdx < charIdx) { 2952 emitText(); 2953 } 2954 // For debugging: search for other "For debugging" lines 2955 // console.log( '\n' + table.toString() ); 2956 // Called when non-tags are being read (i.e. the text around HTML â ags) 2957 // https://www.w3.org/TR/html51/syntax.html#data-state
vendor: 21,805 bytes, lines 2958-3465
2958 function stateData(char) { 2959 if (char === '<') { 2960 startNewTag(); 2961 } 2962 } 2963 // Called after a '<' is read from the Data state 2964 // https://www.w3.org/TR/html51/syntax.html#tag-open-state 2965 function stateTagOpen(char) { 2966 if (char === '!') { 2967 state = 13 /* MarkupDeclarationOpenState */; 2968 } 2969 else if (char === '/') { 2970 state = 2 /* EndTagOpen */; 2971 currentTag = new CurrentTag(__assign(__assign({}, currentTag), { isClosing: true })); 2972 } 2973 else if (char === '<') { 2974 // start of another tag (ignore the previous, incomplete one) 2975 startNewTag(); 2976 } 2977 else if (letterRe.test(char)) { 2978 // tag name start (and no '/' read) 2979 state = 3 /* TagName */; 2980 currentTag = new CurrentTag(__assign(__assign({}, currentTag), { isOpening: true })); 2981 } 2982 else { 2983 // Any other 2984 state = 0 /* Data */; 2985 currentTag = noCurrentTag; 2986 } 2987 } 2988 // After a '<x', '</x' sequence is read (where 'x' is a letter character), 2989 // this is to continue reading the tag name 2990 // https://www.w3.org/TR/html51/syntax.html#tag-name-state 2991 function stateTagName(char) { 2992 if (whitespaceRe.test(char)) { 2993 currentTag = new CurrentTag(__assign(__assign({}, currentTag), { name: captureTagName() })); 2994 state = 4 /* BeforeAttributeName */; 2995 } 2996 else if (char === '<') { 2997 // start of another tag (ignore the previous, incomplete one) 2998 startNewTag(); 2999 } 3000 else if (char === '/') { 3001 currentTag = new CurrentTag(__assign(__assign({}, currentTag), { name: captureTagName() })); 3002 state = 12 /* SelfClosingStartTag */; 3003 } 3004 else if (char === '>') { 3005 currentTag = new CurrentTag(__assign(__assign({}, currentTag), { name: captureTagName() })); 3006 emitTagAndPreviousTextNode(); // resets to Data state as well 3007 } 3008 else if (!letterRe.test(char) && !digitRe.test(char) && char !== ':') { 3009 // Anything else that does not form an html tag. Note: the colon 3010 // character is accepted for XML namespaced tags 3011 resetToDataState(); 3012 } 3013 } 3014 // Called after the '/' is read from a '</' sequence 3015 // https://www.w3.org/TR/html51/syntax.html#end-tag-open-state 3016 function stateEndTagOpen(char) { 3017 if (char === '>') { // parse error. Encountered "</>". Skip it without treating as a tag 3018 resetToDataState(); 3019 } 3020 else if (letterRe.test(char)) { 3021 state = 3 /* TagName */; 3022 } 3023 else { 3024 // some other non-tag-like character, don't treat this as a tag 3025 resetToDataState(); 3026 } 3027 } 3028 // https://www.w3.org/TR/html51/syntax.html#before-attribute-name-state 3029 function stateBeforeAttributeName(char) { 3030 if (whitespaceRe.test(char)) ; 3031 else if (char === '/') { 3032 state = 12 /* SelfClosingStartTag */; 3033 } 3034 else if (char === '>') { 3035 emitTagAndPreviousTextNode(); // resets to Data state as well 3036 } 3037 else if (char === '<') { 3038 // start of another tag (ignore the previous, incomplete one) 3039 startNewTag(); 3040 } 3041 else if (char === "=" || quoteRe.test(char) || controlCharsRe.test(char)) { 3042 // "Parse error" characters that, according to the spec, should be 3043 // appended to the attribute name, but we'll treat these characters 3044 // as not forming a real HTML tag 3045 resetToDataState(); 3046 } 3047 else { 3048 // Any other char, start of a new attribute name 3049 state = 5 /* AttributeName */; 3050 } 3051 } 3052 // https://www.w3.org/TR/html51/syntax.html#attribute-name-state 3053 function stateAttributeName(char) { 3054 if (whitespaceRe.test(char)) { 3055 state = 6 /* AfterAttributeName */; 3056 } 3057 else if (char === '/') { 3058 state = 12 /* SelfClosingStartTag */; 3059 } 3060 else if (char === '=') { 3061 state = 7 /* BeforeAttributeValue */; 3062 } 3063 else if (char === '>') { 3064 emitTagAndPreviousTextNode(); // resets to Data state as well 3065 } 3066 else if (char === '<') { 3067 // start of another tag (ignore the previous, incomplete one) 3068 startNewTag(); 3069 } 3070 else if (quoteRe.test(char)) { 3071 // "Parse error" characters that, according to the spec, should be 3072 // appended to the attribute name, but we'll treat these characters 3073 // as not forming a real HTML tag 3074 resetToDataState(); 3075 } 3076 } 3077 // https://www.w3.org/TR/html51/syntax.html#after-attribute-name-state 3078 function stateAfterAttributeName(char) { 3079 if (whitespaceRe.test(char)) ; 3080 else if (char === '/') { 3081 state = 12 /* SelfClosingStartTag */; 3082 } 3083 else if (char === '=') { 3084 state = 7 /* BeforeAttributeValue */; 3085 } 3086 else if (char === '>') { 3087 emitTagAndPreviousTextNode(); 3088 } 3089 else if (char === '<') { 3090 // start of another tag (ignore the previous, incomplete one) 3091 startNewTag(); 3092 } 3093 else if (quoteRe.test(char)) { 3094 // "Parse error" characters that, according to the spec, should be 3095 // appended to the attribute name, but we'll treat these characters 3096 // as not forming a real HTML tag 3097 resetToDataState(); 3098 } 3099 else { 3100 // Any other character, start a new attribute in the current tag 3101 state = 5 /* AttributeName */; 3102 } 3103 } 3104 // https://www.w3.org/TR/html51/syntax.html#before-attribute-value-state 3105 function stateBeforeAttributeValue(char) { 3106 if (whitespaceRe.test(char)) ; 3107 else if (char === "\"") { 3108 state = 8 /* AttributeValueDoubleQuoted */; 3109 } 3110 else if (char === "'") { 3111 state = 9 /* AttributeValueSingleQuoted */; 3112 } 3113 else if (/[>=`]/.test(char)) { 3114 // Invalid chars after an '=' for an attribute value, don't count 3115 // the current tag as an HTML tag 3116 resetToDataState(); 3117 } 3118 else if (char === '<') { 3119 // start of another tag (ignore the previous, incomplete one) 3120 startNewTag(); 3121 } 3122 else { 3123 // Any other character, consider it an unquoted attribute value 3124 state = 10 /* AttributeValueUnquoted */; 3125 } 3126 } 3127 // https://www.w3.org/TR/html51/syntax.html#attribute-value-double-quoted-state 3128 function stateAttributeValueDoubleQuoted(char) { 3129 if (char === "\"") { // end the current double-quoted attribute 3130 state = 11 /* AfterAttributeValueQuoted */; 3131 } 3132 } 3133 // https://www.w3.org/TR/html51/syntax.html#attribute-value-single-quoted-state 3134 function stateAttributeValueSingleQuoted(char) { 3135 if (char === "'") { // end the current single-quoted attribute 3136 state = 11 /* AfterAttributeValueQuoted */; 3137 } 3138 } 3139 // https://www.w3.org/TR/html51/syntax.html#attribute-value-unquoted-state 3140 function stateAttributeValueUnquoted(char) { 3141 if (whitespaceRe.test(char)) { 3142 state = 4 /* BeforeAttributeName */; 3143 } 3144 else if (char === '>') { 3145 emitTagAndPreviousTextNode(); 3146 } 3147 else if (char === '<') { 3148 // start of another tag (ignore the previous, incomplete one) 3149 startNewTag(); 3150 } 3151 } 3152 // https://www.w3.org/TR/html51/syntax.html#after-attribute-value-quoted-state 3153 function stateAfterAttributeValueQuoted(char) { 3154 if (whitespaceRe.test(char)) { 3155 state = 4 /* BeforeAttributeName */; 3156 } 3157 else if (char === '/') { 3158 state = 12 /* SelfClosingStartTag */; 3159 } 3160 else if (char === '>') { 3161 emitTagAndPreviousTextNode(); 3162 } 3163 else if (char === '<') { 3164 // start of another tag (ignore the previous, incomplete one) 3165 startNewTag(); 3166 } 3167 else { 3168 // Any other character, "parse error". Spec says to switch to the 3169 // BeforeAttributeState and re-consume the character, as it may be 3170 // the start of a new attribute name 3171 state = 4 /* BeforeAttributeName */; 3172 reconsumeCurrentCharacter(); 3173 } 3174 } 3175 // A '/' has just been read in the current tag (presumably for '/>'), and 3176 // this handles the next character 3177 // https://www.w3.org/TR/html51/syntax.html#self-closing-start-tag-state 3178 function stateSelfClosingStartTag(char) { 3179 if (char === '>') { 3180 currentTag = new CurrentTag(__assign(__assign({}, currentTag), { isClosing: true })); 3181 emitTagAndPreviousTextNode(); // resets to Data state as well 3182 } 3183 else { 3184 state = 4 /* BeforeAttributeName */; 3185 } 3186 } 3187 // https://www.w3.org/TR/html51/syntax.html#markup-declaration-open-state 3188 // (HTML Comments or !DOCTYPE) 3189 function stateMarkupDeclarationOpen(char) { 3190 if (html.substr(charIdx, 2) === '--') { // html comment 3191 charIdx += 2; // "consume" characters 3192 currentTag = new CurrentTag(__assign(__assign({}, currentTag), { type: 'comment' })); 3193 state = 14 /* CommentStart */; 3194 } 3195 else if (html.substr(charIdx, 7).toUpperCase() === 'DOCTYPE') { 3196 charIdx += 7; // "consume" characters 3197 currentTag = new CurrentTag(__assign(__assign({}, currentTag), { type: 'doctype' })); 3198 state = 20 /* Doctype */; 3199 } 3200 else { 3201 // At this point, the spec specifies that the state machine should 3202 // enter the "bogus comment" state, in which case any character(s) 3203 // after the '<!' that were read should become an HTML comment up 3204 // until the first '>' that is read (or EOF). Instead, we'll assume 3205 // that a user just typed '<!' as part of text data 3206 resetToDataState(); 3207 } 3208 } 3209 // Handles after the sequence '<!--' has been read 3210 // https://www.w3.org/TR/html51/syntax.html#comment-start-state 3211 function stateCommentStart(char) { 3212 if (char === '-') { 3213 // We've read the sequence '<!---' at this point (3 dashes) 3214 state = 15 /* CommentStartDash */; 3215 } 3216 else if (char === '>') { 3217 // At this point, we'll assume the comment wasn't a real comment 3218 // so we'll just emit it as data. We basically read the sequence 3219 // '<!-->' 3220 resetToDataState(); 3221 } 3222 else { 3223 // Any other char, take it as part of the comment 3224 state = 16 /* Comment */; 3225 } 3226 } 3227 // We've read the sequence '<!---' at this point (3 dashes) 3228 // https://www.w3.org/TR/html51/syntax.html#comment-start-dash-state 3229 function stateCommentStartDash(char) { 3230 if (char === '-') { 3231 // We've read '<!----' (4 dashes) at this point 3232 state = 18 /* CommentEnd */; 3233 } 3234 else if (char === '>') { 3235 // At this point, we'll assume the comment wasn't a real comment 3236 // so we'll just emit it as data. We basically read the sequence 3237 // '<!--->' 3238 resetToDataState(); 3239 } 3240 else { 3241 // Anything else, take it as a valid comment 3242 state = 16 /* Comment */; 3243 } 3244 } 3245 // Currently reading the comment's text (data) 3246 // https://www.w3.org/TR/html51/syntax.html#comment-state 3247 function stateComment(char) { 3248 if (char === '-') { 3249 state = 17 /* CommentEndDash */; 3250 } 3251 } 3252 // When we we've read the first dash inside a comment, it may signal the 3253 // end of the comment if we read another dash 3254 // https://www.w3.org/TR/html51/syntax.html#comment-end-dash-state 3255 function stateCommentEndDash(char) { 3256 if (char === '-') { 3257 state = 18 /* CommentEnd */; 3258 } 3259 else { 3260 // Wasn't a dash, must still be part of the comment 3261 state = 16 /* Comment */; 3262 } 3263 } 3264 // After we've read two dashes inside a comment, it may signal the end of 3265 // the comment if we then read a '>' char 3266 // https://www.w3.org/TR/html51/syntax.html#comment-end-state 3267 function stateCommentEnd(char) { 3268 if (char === '>') { 3269 emitTagAndPreviousTextNode(); 3270 } 3271 else if (char === '!') { 3272 state = 19 /* CommentEndBang */; 3273 } 3274 else if (char === '-') ; 3275 else { 3276 // Anything else, switch back to the comment state since we didn't 3277 // read the full "end comment" sequence (i.e. '-->') 3278 state = 16 /* Comment */; 3279 } 3280 } 3281 // We've read the sequence '--!' inside of a comment 3282 // https://www.w3.org/TR/html51/syntax.html#comment-end-bang-state 3283 function stateCommentEndBang(char) { 3284 if (char === '-') { 3285 // We read the sequence '--!-' inside of a comment. The last dash 3286 // could signify that the comment is going to close 3287 state = 17 /* CommentEndDash */; 3288 } 3289 else if (char === '>') { 3290 // End of comment with the sequence '--!>' 3291 emitTagAndPreviousTextNode(); 3292 } 3293 else { 3294 // The '--!' was not followed by a '>', continue reading the 3295 // comment's text 3296 state = 16 /* Comment */; 3297 } 3298 } 3299 /** 3300 * For DOCTYPES in particular, we don't care about the attributes. Just 3301 * advance to the '>' character and emit the tag, unless we find a '<' 3302 * character in which case we'll start a new tag. 3303 * 3304 * Example doctype tag: 3305 * <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 3306 * 3307 * Actual spec: https://www.w3.org/TR/html51/syntax.html#doctype-state 3308 */ 3309 function stateDoctype(char) { 3310 if (char === '>') { 3311 emitTagAndPreviousTextNode(); 3312 } 3313 else if (char === '<') { 3314 startNewTag(); 3315 } 3316 } 3317 /** 3318 * Resets the state back to the Data state, and removes the current tag. 3319 * 3320 * We'll generally run this function whenever a "parse error" is 3321 * encountered, where the current tag that is being read no longer looks 3322 * like a real HTML tag. 3323 */ 3324 function resetToDataState() { 3325 state = 0 /* Data */; 3326 currentTag = noCurrentTag; 3327 } 3328 /** 3329 * Starts a new HTML tag at the current index, ignoring any previous HTML 3330 * tag that was being read. 3331 * 3332 * We'll generally run this function whenever we read a new '<' character, 3333 * including when we read a '<' character inside of an HTML tag that we were 3334 * previously reading. 3335 */ 3336 function startNewTag() { 3337 state = 1 /* TagOpen */; 3338 currentTag = new CurrentTag({ idx: charIdx }); 3339 } 3340 /** 3341 * Once we've decided to emit an open tag, that means we can also emit the 3342 * text node before it. 3343 */ 3344 function emitTagAndPreviousTextNode() { 3345 var textBeforeTag = html.slice(currentDataIdx, currentTag.idx); 3346 if (textBeforeTag) { 3347 // the html tag was the first element in the html string, or two 3348 // tags next to each other, in which case we should not emit a text 3349 // node 3350 onText(textBeforeTag, currentDataIdx); 3351 } 3352 if (currentTag.type === 'comment') { 3353 onComment(currentTag.idx); 3354 } 3355 else if (currentTag.type === 'doctype') { 3356 onDoctype(currentTag.idx); 3357 } 3358 else { 3359 if (currentTag.isOpening) { 3360 onOpenTag(currentTag.name, currentTag.idx); 3361 } 3362 if (currentTag.isClosing) { // note: self-closing tags will emit both opening and closing 3363 onCloseTag(currentTag.name, currentTag.idx); 3364 } 3365 } 3366 // Since we just emitted a tag, reset to the data state for the next char 3367 resetToDataState(); 3368 currentDataIdx = charIdx + 1; 3369 } 3370 function emitText() { 3371 var text = html.slice(currentDataIdx, charIdx); 3372 onText(text, currentDataIdx); 3373 currentDataIdx = charIdx + 1; 3374 } 3375 /** 3376 * Captures the tag name from the start of the tag to the current character 3377 * index, and converts it to lower case 3378 */ 3379 function captureTagName() { 3380 var startIdx = currentTag.idx + (currentTag.isClosing ? 2 : 1); 3381 return html.slice(startIdx, charIdx).toLowerCase(); 3382 } 3383 /** 3384 * Causes the main loop to re-consume the current character, such as after 3385 * encountering a "parse error" that changed state and needs to reconsume 3386 * the same character in that new state. 3387 */ 3388 function reconsumeCurrentCharacter() { 3389 charIdx--; 3390 } 3391 } 3392 var CurrentTag = /** @class */ (function () { 3393 function CurrentTag(cfg) { 3394 if (cfg === void 0) { cfg = {}; } 3395 this.idx = cfg.idx !== undefined ? cfg.idx : -1; 3396 this.type = cfg.type || 'tag'; 3397 this.name = cfg.name || ''; 3398 this.isOpening = !!cfg.isOpening; 3399 this.isClosing = !!cfg.isClosing; 3400 } 3401 return CurrentTag; 3402 }()); 3403 3404 /** 3405 * @class Autolinker 3406 * @extends Object 3407 * 3408 * Utility class used to process a given string of text, and wrap the matches in 3409 * the appropriate anchor (<a>) tags to turn them into links. 3410 * 3411 * Any of the configuration options may be provided in an Object provided 3412 * to the Autolinker constructor, which will configure how the {@link #link link()} 3413 * method will process the links. 3414 * 3415 * For example: 3416 * 3417 * var autolinker = new Autolinker( { 3418 * newWindow : false, 3419 * truncate : 30 3420 * } ); 3421 * 3422 * var html = autolinker.link( "Joe went to www.yahoo.com" ); 3423 * // produces: 'Joe went to <a href="http://www.yahoo.com">yahoo.com</a>' 3424 * 3425 * 3426 * The {@link #static-link static link()} method may also be used to inline 3427 * options into a single call, which may be more convenient for one-off uses. 3428 * For example: 3429 * 3430 * var html = Autolinker.link( "Joe went to www.yahoo.com", { 3431 * newWindow : false, 3432 * truncate : 30 3433 * } ); 3434 * // produces: 'Joe went to <a href="http://www.yahoo.com">yahoo.com</a>' 3435 * 3436 * 3437 * ## Custom Replacements of Links 3438 * 3439 * If the configuration options do not provide enough flexibility, a {@link #replaceFn} 3440 * may be provided to fully customize the output of Autolinker. This function is 3441 * called once for each URL/Email/Phone#/Hashtag/Mention (Twitter, Instagram, Soundcloud) 3442 * match that is encountered. 3443 * 3444 * For example: 3445 * 3446 * var input = "..."; // string with URLs, Email Addresses, Phone #s, Hashtags, and Mentions (Twitter, Instagram, Soundcloud) 3447 * 3448 * var linkedText = Autolinker.link( input, { 3449 * replaceFn : function( match ) { 3450 * console.log( "href = ", match.getAnchorHref() ); 3451 * console.log( "text = ", match.getAnchorText() ); 3452 * 3453 * switch( match.getType() ) { 3454 * case 'url' : 3455 * console.log( "url: ", match.getUrl() ); 3456 * 3457 * if( match.getUrl().indexOf( 'mysite.com' ) === -1 ) { 3458 * var tag = match.buildTag(); // returns an `Autolinker.HtmlTag` instance, which provides mutator methods for easy changes 3459 * tag.setAttr( 'rel', 'nofollow' ); 3460 * tag.addClass( 'external-link' ); 3461 * 3462 * return tag; 3463 * 3464 * } else { 3465 * return true;
3465 // let Autolinker perform its normal anchor tag replacement 3466 * } 3467 * 3468 * case 'email' : 3469 * var email = match.getEmail(); 3470 * console.log( "email: ", email ); 3471 * 3472 * if( email === "[email protected]" ) { 3473 * return false; // don't auto-link this particular email address; leave as-is 3474 * } else { 3475 * return; // no return value will have Autolinker perform its normal anchor tag replacement (same as returning `true`) 3476 * } 3477 * 3478 * case 'phone' : 3479 * var phoneNumber = match.getPhoneNumber(); 3480 * console.log( phoneNumber ); 3481 * 3482 * return '<a href="http://newplace.to.link.phone.numbers.to/">' + phoneNumber + '</a>'; 3483 * 3484 * case 'hashtag' : 3485 * var hashtag = match.getHashtag(); 3486 * console.log( hashtag ); 3487 * 3488 * return '<a href="http://newplace.to.link.hashtag.handles.to/">' + hashtag + '</a>'; 3489 * 3490 * case 'mention' : 3491 * var mention = match.getMention(); 3492 * console.log( mention ); 3493 * 3494 * return '<a href="http://newplace.to.link.mention.to/">' + mention + '</a>'; 3495 * } 3496 * } 3497 * } ); 3498 * 3499 * 3500 * The function may return the following values: 3501 * 3502 * - `true` (Boolean): Allow Autolinker to replace the match as it normally 3503 * would. 3504 * - `false` (Boolean): Do not replace the current match at all - leave as-is. 3505 * - Any String: If a string is returned from the function, the string will be 3506 * used directly as the replacement HTML for the match. 3507 * - An {@link Autolinker.HtmlTag} instance, which can be used to build/modify 3508 * an HTML tag before writing out its HTML text. 3509 */ 3510 var Autolinker = /** @class */ (function () { 3511 /** 3512 * @method constructor 3513 * @param {Object} [cfg] The configuration options for the Autolinker instance, 3514 * specified in an Object (map). 3515 */ 3516 function Autolinker(cfg) { 3517 if (cfg === void 0) { cfg = {}; } 3518 /** 3519 * The Autolinker version number exposed on the instance itself. 3520 * 3521 * Ex: 0.25.1 3522 */ 3523 this.version = Autolinker.version; 3524 /** 3525 * @cfg {Boolean/Object} [urls] 3526 * 3527 * `true` if URLs should be automatically linked, `false` if they should not 3528 * be. Defaults to `true`. 3529 * 3530 * Examples: 3531 * 3532 * urls: true 3533 * 3534 * // or 3535 * 3536 * urls: { 3537 * schemeMatches : true, 3538 * wwwMatches : true, 3539 * tldMatches : true 3540 * } 3541 * 3542 * As shown above, this option also accepts an Object form with 3 properties 3543 * to allow for more customization of what exactly gets linked. All default 3544 * to `true`: 3545 * 3546 * @cfg {Boolean} [urls.schemeMatches] `true` to match URLs found prefixed 3547 * with a scheme, i.e. `http://google.com`, or `other+scheme://google.com`, 3548 * `false` to prevent these types of matches. 3549 * @cfg {Boolean} [urls.wwwMatches] `true` to match urls found prefixed with 3550 * `'www.'`, i.e. `www.google.com`. `false` to prevent these types of 3551 * matches. Note that if the URL had a prefixed scheme, and 3552 * `schemeMatches` is true, it will still be linked. 3553 * @cfg {Boolean} [urls.tldMatches] `true` to match URLs with known top 3554 * level domains (.com, .net, etc.) that are not prefixed with a scheme or 3555 * `'www.'`. This option attempts to match anything that looks like a URL 3556 * in the given text. Ex: `google.com`, `asdf.org/?page=1`, etc. `false` 3557 * to prevent these types of matches. 3558 */ 3559 this.urls = {}; // default value just to get the above doc comment in the ES5 output and documentation generator 3560 /** 3561 * @cfg {Boolean} [email=true] 3562 * 3563 * `true` if email addresses should be automatically linked, `false` if they 3564 * should not be. 3565 */ 3566 this.email = true; // default value just to get the above doc comment in the ES5 output and documentation generator 3567 /** 3568 * @cfg {Boolean} [phone=true] 3569 * 3570 * `true` if Phone numbers ("(555)555-5555") should be automatically linked, 3571 * `false` if they should not be. 3572 */ 3573 this.phone = true; // default value just to get the above doc comment in the ES5 output and documentation generator 3574 /** 3575 * @cfg {Boolean/String} [hashtag=false] 3576 * 3577 * A string for the service name to have hashtags (ex: "#myHashtag") 3578 * auto-linked to. The currently-supported values are: 3579 * 3580 * - 'twitter' 3581 * - 'facebook' 3582 * - 'instagram' 3583 * 3584 * Pass `false` to skip auto-linking of hashtags. 3585 */ 3586 this.hashtag = false; // default value just to get the above doc comment in the ES5 output and documentation generator 3587 /** 3588 * @cfg {String/Boolean} [mention=false] 3589 * 3590 * A string for the service name to have mentions (ex: "@myuser") 3591 * auto-linked to. The currently supported values are: 3592 * 3593 * - 'twitter' 3594 * - 'instagram' 3595 * - 'soundcloud' 3596 * 3597 * Defaults to `false` to skip auto-linking of mentions. 3598 */ 3599 this.mention = false; // default value just to get the above doc comment in the ES5 output and documentation generator 3600 /** 3601 * @cfg {Boolean} [newWindow=true] 3602 * 3603 * `true` if the links should open in a new window, `false` otherwise. 3604 */ 3605 this.newWindow = true; // default value just to get the above doc comment in the ES5 output and documentation generator 3606 /** 3607 * @cfg {Boolean/Object} [stripPrefix=true] 3608 * 3609 * `true` if 'http://' (or 'https://') and/or the 'www.' should be stripped 3610 * from the beginning of URL links' text, `false` otherwise. Defaults to 3611 * `true`. 3612 * 3613 * Examples: 3614 * 3615 * stripPrefix: true 3616 * 3617 * // or 3618 * 3619 * stripPrefix: { 3620 * scheme : true, 3621 * www : true 3622 * } 3623 * 3624 * As shown above, this option also accepts an Object form with 2 properties 3625 * to allow for more customization of what exactly is prevented from being 3626 * displayed. Both default to `true`: 3627 * 3628 * @cfg {Boolean} [stripPrefix.scheme] `true` to prevent the scheme part of 3629 * a URL match from being displayed to the user. Example: 3630 * `'http://google.com'` will be displayed as `'google.com'`. `false` to 3631 * not strip the scheme. NOTE: Only an `'http://'` or `'https://'` scheme 3632 * will be removed, so as not to remove a potentially dangerous scheme 3633 * (such as `'file://'` or `'javascript:'`) 3634 * @cfg {Boolean} [stripPrefix.www] www (Boolean): `true` to prevent the 3635 * `'www.'` part of a URL match from being displayed to the user. Ex: 3636 * `'www.google.com'` will be displayed as `'google.com'`. `false` to not 3637 * strip the `'www'`. 3638 */ 3639 this.stripPrefix = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator 3640 /** 3641 * @cfg {Boolean} [stripTrailingSlash=true] 3642 * 3643 * `true` to remove the trailing slash from URL matches, `false` to keep 3644 * the trailing slash. 3645 * 3646 * Example when `true`: `http://google.com/` will be displayed as 3647 * `http://google.com`. 3648 */ 3649 this.stripTrailingSlash = true; // default value just to get the above doc comment in the ES5 output and documentation generator 3650 /** 3651 * @cfg {Boolean} [decodePercentEncoding=true] 3652 * 3653 * `true` to decode percent-encoded characters in URL matches, `false` to keep 3654 * the percent-encoded characters. 3655 * 3656 * Example when `true`: `https://en.wikipedia.org/wiki/San_Jos%C3%A9` will 3657 * be displayed as `https://en.wikipedia.org/wiki/San_José`. 3658 */ 3659 this.decodePercentEncoding = true; // default value just to get the above doc comment in the ES5 output and documentation generator 3660 /** 3661 * @cfg {Number/Object} [truncate=0] 3662 * 3663 * ## Number Form 3664 * 3665 * A number for how many characters matched text should be truncated to 3666 * inside the text of a link. If the matched text is over this number of 3667 * characters, it will be truncated to this length by adding a two period 3668 * ellipsis ('..') to the end of the string. 3669 * 3670 * For example: A url like 'http://www.yahoo.com/some/long/path/to/a/file'
3671 * truncated to 25 characters might look something like this: 3672 * 'yahoo.com/some/long/pat..' 3673 * 3674 * Example Usage: 3675 * 3676 * truncate: 25 3677 * 3678 * 3679 * Defaults to `0` for "no truncation." 3680 * 3681 * 3682 * ## Object Form 3683 * 3684 * An Object may also be provided with two properties: `length` (Number) and 3685 * `location` (String). `location` may be one of the following: 'end' 3686 * (default), 'middle', or 'smart'. 3687 * 3688 * Example Usage: 3689 * 3690 * truncate: { length: 25, location: 'middle' } 3691 * 3692 * @cfg {Number} [truncate.length=0] How many characters to allow before 3693 * truncation will occur. Defaults to `0` for "no truncation." 3694 * @cfg {"end"/"middle"/"smart"} [truncate.location="end"] 3695 * 3696 * - 'end' (default): will truncate up to the number of characters, and then 3697 * add an ellipsis at the end. Ex: 'yahoo.com/some/long/pat..' 3698 * - 'middle': will truncate and add the ellipsis in the middle. Ex: 3699 * 'yahoo.com/s..th/to/a/file' 3700 * - 'smart': for URLs where the algorithm attempts to strip out unnecessary 3701 * parts first (such as the 'www.', then URL scheme, hash, etc.), 3702 * attempting to make the URL human-readable before looking for a good 3703 * point to insert the ellipsis if it is still too long. Ex: 3704 * 'yahoo.com/some..to/a/file'. For more details, see 3705 * {@link Autolinker.truncate.TruncateSmart}. 3706 */ 3707 this.truncate = { length: 0, location: 'end' }; // default value just to get the above doc comment in the ES5 output and documentation generator 3708 /** 3709 * @cfg {String} className 3710 * 3711 * A CSS class name to add to the generated links. This class will be added 3712 * to all links, as well as this class plus match suffixes for styling 3713 * url/email/phone/hashtag/mention links differently. 3714 * 3715 * For example, if this config is provided as "myLink", then: 3716 * 3717 * - URL links will have the CSS classes: "myLink myLink-url" 3718 * - Email links will have the CSS classes: "myLink myLink-email", and 3719 * - Phone links will have the CSS classes: "myLink myLink-phone" 3720 * - Hashtag links will have the CSS classes: "myLink myLink-hashtag" 3721 * - Mention links will have the CSS classes: "myLink myLink-mention myLink-[type]" 3722 * where [type] is either "instagram", "twitter" or "soundcloud" 3723 */ 3724 this.className = ''; // default value just to get the above doc comment in the ES5 output and documentation generator 3725 /** 3726 * @cfg {Function} replaceFn 3727 * 3728 * A function to individually process each match found in the input string. 3729 * 3730 * See the class's description for usage. 3731 * 3732 * The `replaceFn` can be called with a different context object (`this` 3733 * reference) using the {@link #context} cfg. 3734 * 3735 * This function is called with the following parameter: 3736 * 3737 * @cfg {Autolinker.match.Match} replaceFn.match The Match instance which 3738 * can be used to retrieve information about the match that the `replaceFn` 3739 * is currently processing. See {@link Autolinker.match.Match} subclasses 3740 * for details. 3741 */ 3742 this.replaceFn = null; // default value just to get the above doc comment in the ES5 output and documentation generator 3743 /** 3744 * @cfg {Object} context 3745 * 3746 * The context object (`this` reference) to call the `replaceFn` with. 3747 * 3748 * Defaults to this Autolinker instance. 3749 */ 3750 this.context = undefined; // default value just to get the above doc comment in the ES5 output and documentation generator 3751 /** 3752 * @cfg {Boolean} [sanitizeHtml=false] 3753 * 3754 * `true` to HTML-encode the start and end brackets of existing HTML tags found 3755 * in the input string. This will escape `<` and `>` characters to `<` and 3756 * `>`, respectively. 3757 * 3758 * Setting this to `true` will prevent XSS (Cross-site Scripting) attacks, 3759 * but will remove the significance of existing HTML tags in the input string. If 3760 * you would like to maintain the significance of existing HTML tags while also 3761 * making the output HTML string safe, leave this option as `false` and use a 3762 * tool like https://github.com/cure53/DOMPurify (or others) on the input string 3763 * before running Autolinker. 3764 */ 3765 this.sanitizeHtml = false; // default value just to get the above doc comment in the ES5 output and documentation generator 3766 /** 3767 * @private 3768 * @property {Autolinker.matcher.Matcher[]} matchers 3769 * 3770 * The {@link Autolinker.matcher.Matcher} instances for this Autolinker 3771 * instance. 3772 * 3773 * This is lazily created in {@link #getMatchers}. 3774 */ 3775 this.matchers = null; 3776 /** 3777 * @private 3778 * @property {Autolinker.AnchorTagBuilder} tagBuilder 3779 * 3780 * The AnchorTagBuilder instance used to build match replacement anchor tags. 3781 * Note: this is lazily instantiated in the {@link #getTagBuilder} method. 3782 */ 3783 this.tagBuilder = null; 3784 // Note: when `this.something` is used in the rhs of these assignments, 3785 // it refers to the default values set above the constructor 3786 this.urls = this.normalizeUrlsCfg(cfg.urls); 3787 this.email = typeof cfg.email === 'boolean' ? cfg.email : this.email; 3788 this.phone = typeof cfg.phone === 'boolean' ? cfg.phone : this.phone; 3789 this.hashtag = cfg.hashtag || this.hashtag; 3790 this.mention = cfg.mention || this.mention; 3791 this.newWindow = typeof cfg.newWindow === 'boolean' ? cfg.newWindow : this.newWindow; 3792 this.stripPrefix = this.normalizeStripPrefixCfg(cfg.stripPrefix); 3793 this.stripTrailingSlash = typeof cfg.stripTrailingSlash === 'boolean' ? cfg.stripTrailingSlash : this.stripTrailingSlash; 3794 this.decodePercentEncoding = typeof cfg.decodePercentEncoding === 'boolean' ? cfg.decodePercentEncoding : this.decodePercentEncoding; 3795 this.sanitizeHtml = cfg.sanitizeHtml || false; 3796 // Validate the value of the `mention` cfg 3797 var mention = this.mention; 3798 if (mention !== false && mention !== 'twitter' && mention !== 'instagram' && mention !== 'soundcloud') { 3799 throw new Error("invalid `mention` cfg - see docs"); 3800 } 3801 // Validate the value of the `hashtag` cfg 3802 var hashtag = this.hashtag; 3803 if (hashtag !== false && hashtag !== 'twitter' && hashtag !== 'facebook' && hashtag !== 'instagram') { 3804 throw new Error("invalid `hashtag` cfg - see docs"); 3805 } 3806 this.truncate = this.normalizeTruncateCfg(cfg.truncate); 3807 this.className = cfg.className || this.className; 3808 this.replaceFn = cfg.replaceFn || this.replaceFn; 3809 this.context = cfg.context || this; 3810 } 3811 /** 3812 * Automatically links URLs, Email addresses, Phone Numbers, Twitter handles,
3813 * Hashtags, and Mentions found in the given chunk of HTML. Does not link URLs 3814 * found within HTML tags. 3815 * 3816 * For instance, if given the text: `You should go to http://www.yahoo.com`, 3817 * then the result will be `You should go to <a href="http://www.yahoo.com">http://www.yahoo.com</a>` 3818 * 3819 * Example: 3820 * 3821 * var linkedText = Autolinker.link( "Go to google.com", { newWindow: false } ); 3822 * // Produces: "Go to <a href="http://google.com">google.com</a>" 3823 * 3824 * @static 3825 * @param {String} textOrHtml The HTML or text to find matches within (depending 3826 * on if the {@link #urls}, {@link #email}, {@link #phone}, {@link #mention}, 3827 * {@link #hashtag}, and {@link #mention} options are enabled). 3828 * @param {Object} [options] Any of the configuration options for the Autolinker 3829 * class, specified in an Object (map). See the class description for an 3830 * example call. 3831 * @return {String} The HTML text, with matches automatically linked. 3832 */ 3833 Autolinker.link = function (textOrHtml, options) { 3834 var autolinker = new Autolinker(options); 3835 return autolinker.link(textOrHtml); 3836 }; 3837 /** 3838 * Parses the input `textOrHtml` looking for URLs, email addresses, phone 3839 * numbers, username handles, and hashtags (depending on the configuration 3840 * of the Autolinker instance), and returns an array of {@link Autolinker.match.Match} 3841 * objects describing those matches (without making any replacements). 3842 * 3843 * Note that if parsing multiple pieces of text, it is slightly more efficient 3844 * to create an Autolinker instance, and use the instance-level {@link #parse} 3845 * method. 3846 * 3847 * Example: 3848 * 3849 * var matches = Autolinker.parse( "Hello google.com, I am [email protected]", { 3850 * urls: true, 3851 * email: true 3852 * } ); 3853 * 3854 * console.log( matches.length ); // 2 3855 * console.log( matches[ 0 ].getType() ); // 'url' 3856 * console.log( matches[ 0 ].getUrl() ); // 'google.com' 3857 * console.log( matches[ 1 ].getType() ); // 'email' 3858 * console.log( matches[ 1 ].getEmail() ); // '[email protected]' 3859 * 3860 * @static 3861 * @param {String} textOrHtml The HTML or text to find matches within 3862 * (depending on if the {@link #urls}, {@link #email}, {@link #phone}, 3863 * {@link #hashtag}, and {@link #mention} options are enabled). 3864 * @param {Object} [options] Any of the configuration options for the Autolinker 3865 * class, specified in an Object (map). See the class description for an 3866 * example call. 3867 * @return {Autolinker.match.Match[]} The array of Matches found in the 3868 * given input `textOrHtml`. 3869 */ 3870 Autolinker.parse = function (textOrHtml, options) { 3871 var autolinker = new Autolinker(options); 3872 return autolinker.parse(textOrHtml); 3873 }; 3874 /** 3875 * Normalizes the {@link #urls} config into an Object with 3 properties: 3876 * `schemeMatches`, `wwwMatches`, and `tldMatches`, all Booleans. 3877 * 3878 * See {@link #urls} config for details. 3879 * 3880 * @private 3881 * @param {Boolean/Object} urls 3882 * @return {Object} 3883 */ 3884 Autolinker.prototype.normalizeUrlsCfg = function (urls) { 3885 if (urls == null) 3886 urls = true; // default to `true` 3887 if (typeof urls === 'boolean') { 3888 return { schemeMatches: urls, wwwMatches: urls, tldMatches: urls }; 3889 } 3890 else { // object form 3891 return { 3892 schemeMatches: typeof urls.schemeMatches === 'boolean' ? urls.schemeMatches : true, 3893 wwwMatches: typeof urls.wwwMatches === 'boolean' ? urls.wwwMatches : true, 3894 tldMatches: typeof urls.tldMatches === 'boolean' ? urls.tldMatches : true 3895 }; 3896 } 3897 }; 3898 /** 3899 * Normalizes the {@link #stripPrefix} config into an Object with 2 3900 * properties: `scheme`, and `www` - both Booleans. 3901 * 3902 * See {@link #stripPrefix} config for details. 3903 * 3904 * @private 3905 * @param {Boolean/Object} stripPrefix 3906 * @return {Object} 3907 */ 3908 Autolinker.prototype.normalizeStripPrefixCfg = function (stripPrefix) { 3909 if (stripPrefix == null)
vendor: 12,400 bytes, lines 3910-4134
3910 stripPrefix = true; // default to `true` 3911 if (typeof stripPrefix === 'boolean') { 3912 return { scheme: stripPrefix, www: stripPrefix }; 3913 } 3914 else { // object form 3915 return { 3916 scheme: typeof stripPrefix.scheme === 'boolean' ? stripPrefix.scheme : true, 3917 www: typeof stripPrefix.www === 'boolean' ? stripPrefix.www : true 3918 }; 3919 } 3920 }; 3921 /** 3922 * Normalizes the {@link #truncate} config into an Object with 2 properties: 3923 * `length` (Number), and `location` (String). 3924 * 3925 * See {@link #truncate} config for details. 3926 * 3927 * @private 3928 * @param {Number/Object} truncate 3929 * @return {Object} 3930 */ 3931 Autolinker.prototype.normalizeTruncateCfg = function (truncate) { 3932 if (typeof truncate === 'number') { 3933 return { length: truncate, location: 'end' }; 3934 } 3935 else { // object, or undefined/null 3936 return defaults(truncate || {}, { 3937 length: Number.POSITIVE_INFINITY, 3938 location: 'end' 3939 }); 3940 } 3941 }; 3942 /** 3943 * Parses the input `textOrHtml` looking for URLs, email addresses, phone 3944 * numbers, username handles, and hashtags (depending on the configuration 3945 * of the Autolinker instance), and returns an array of {@link Autolinker.match.Match} 3946 * objects describing those matches (without making any replacements). 3947 * 3948 * This method is used by the {@link #link} method, but can also be used to 3949 * simply do parsing of the input in order to discover what kinds of links 3950 * there are and how many. 3951 * 3952 * Example usage: 3953 * 3954 * var autolinker = new Autolinker( { 3955 * urls: true, 3956 * email: true 3957 * } ); 3958 * 3959 * var matches = autolinker.parse( "Hello google.com, I am [email protected]" ); 3960 * 3961 * console.log( matches.length ); // 2 3962 * console.log( matches[ 0 ].getType() ); // 'url' 3963 * console.log( matches[ 0 ].getUrl() ); // 'google.com' 3964 * console.log( matches[ 1 ].getType() ); // 'email' 3965 * console.log( matches[ 1 ].getEmail() ); // '[email protected]' 3966 * 3967 * @param {String} textOrHtml The HTML or text to find matches within 3968 * (depending on if the {@link #urls}, {@link #email}, {@link #phone}, 3969 * {@link #hashtag}, and {@link #mention} options are enabled). 3970 * @return {Autolinker.match.Match[]} The array of Matches found in the 3971 * given input `textOrHtml`. 3972 */ 3973 Autolinker.prototype.parse = function (textOrHtml) { 3974 var _this = this; 3975 var skipTagNames = ['a', 'style', 'script'], skipTagsStackCount = 0, // used to only Autolink text outside of anchor/script/style tags. We don't want to autolink something that is already linked inside of an <a> tag, for instance 3976 matches = []; 3977 // Find all matches within the `textOrHtml` (but not matches that are 3978 // already nested within <a>, <style> and <script> tags) 3979 parseHtml(textOrHtml, { 3980 onOpenTag: function (tagName) { 3981 if (skipTagNames.indexOf(tagName) >= 0) { 3982 skipTagsStackCount++; 3983 } 3984 }, 3985 onText: function (text, offset) { 3986 // Only process text nodes that are not within an <a>, <style> or <script> tag 3987 if (skipTagsStackCount === 0) { 3988 // "Walk around" common HTML entities. An ' ' (for example) 3989 // could be at the end of a URL, but we don't want to 3990 // include the trailing '&' in the URL. See issue #76 3991 // TODO: Handle HTML entities separately in parseHtml() and 3992 // don't emit them as "text" except for & entities 3993 var htmlCharacterEntitiesRegex = /( | |<|<|>|>|"|"|')/gi; 3994 var textSplit = splitAndCapture(text, htmlCharacterEntitiesRegex); 3995 var currentOffset_1 = offset; 3996 textSplit.forEach(function (splitText, i) { 3997 // even number matches are text, odd numbers are html entities 3998 if (i % 2 === 0) { 3999 var textNodeMatches = _this.parseText(splitText, currentOffset_1); 4000 matches.push.apply(matches, textNodeMatches); 4001 } 4002 currentOffset_1 += splitText.length; 4003 }); 4004 } 4005 }, 4006 onCloseTag: function (tagName) { 4007 if (skipTagNames.indexOf(tagName) >= 0) { 4008 skipTagsStackCount = Math.max(skipTagsStackCount - 1, 0); // attempt to handle extraneous </a> tags by making sure the stack count never goes below 0 4009 } 4010 }, 4011 onComment: function (offset) { }, 4012 onDoctype: function (offset) { }, // no need to process doctype nodes 4013 }); 4014 // After we have found all matches, remove subsequent matches that 4015 // overlap with a previous match. This can happen for instance with URLs, 4016 // where the url 'google.com/#link' would match '#link' as a hashtag. 4017 matches = this.compactMatches(matches); 4018 // And finally, remove matches for match types that have been turned 4019 // off. We needed to have all match types turned on initially so that 4020 // things like hashtags could be filtered out if they were really just 4021 // part of a URL match (for instance, as a named anchor). 4022 matches = this.removeUnwantedMatches(matches); 4023 return matches; 4024 }; 4025 /** 4026 * After we have found all matches, we need to remove matches that overlap 4027 * with a previous match. This can happen for instance with URLs, where the 4028 * url 'google.com/#link' would match '#link' as a hashtag. Because the 4029 * '#link' part is contained in a larger match that comes before the HashTag 4030 * match, we'll remove the HashTag match. 4031 * 4032 * @private 4033 * @param {Autolinker.match.Match[]} matches 4034 * @return {Autolinker.match.Match[]} 4035 */ 4036 Autolinker.prototype.compactMatches = function (matches) { 4037 // First, the matches need to be sorted in order of offset 4038 matches.sort(function (a, b) { return a.getOffset() - b.getOffset(); }); 4039 for (var i = 0; i < matches.length - 1; i++) { 4040 var match = matches[i], offset = match.getOffset(), matchedTextLength = match.getMatchedText().length, endIdx = offset + matchedTextLength; 4041 if (i + 1 < matches.length) { 4042 // Remove subsequent matches that equal offset with current match 4043 if (matches[i + 1].getOffset() === offset) { 4044 var removeIdx = matches[i + 1].getMatchedText().length > matchedTextLength ? i : i + 1; 4045 matches.splice(removeIdx, 1); 4046 continue; 4047 } 4048 // Remove subsequent matches that overlap with the current match 4049 if (matches[i + 1].getOffset() < endIdx) { 4050 matches.splice(i + 1, 1); 4051 } 4052 } 4053 } 4054 return matches; 4055 }; 4056 /** 4057 * Removes matches for matchers that were turned off in the options. For 4058 * example, if {@link #hashtag hashtags} were not to be matched, we'll 4059 * remove them from the `matches` array here. 4060 * 4061 * Note: we *must* use all Matchers on the input string, and then filter 4062 * them out later. For example, if the options were `{ url: false, hashtag: true }`, 4063 * we wouldn't want to match the text '#link' as a HashTag inside of the text 4064 * 'google.com/#link'. The way the algorithm works is that we match the full 4065 * URL first (which prevents the accidental HashTag match), and then we'll 4066 * simply throw away the URL match. 4067 * 4068 * @private 4069 * @param {Autolinker.match.Match[]} matches The array of matches to remove 4070 * the unwanted matches from. Note: this array is mutated for the 4071 * removals. 4072 * @return {Autolinker.match.Match[]} The mutated input `matches` array. 4073 */ 4074 Autolinker.prototype.removeUnwantedMatches = function (matches) { 4075 if (!this.hashtag) 4076 remove(matches, function (match) { return match.getType() === 'hashtag'; }); 4077 if (!this.email) 4078 remove(matches, function (match) { return match.getType() === 'email'; }); 4079 if (!this.phone) 4080 remove(matches, function (match) { return match.getType() === 'phone'; }); 4081 if (!this.mention) 4082 remove(matches, function (match) { return match.getType() === 'mention'; }); 4083 if (!this.urls.schemeMatches) { 4084 remove(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'scheme'; }); 4085 } 4086 if (!this.urls.wwwMatches) { 4087 remove(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'www'; }); 4088 } 4089 if (!this.urls.tldMatches) { 4090 remove(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'tld'; }); 4091 } 4092 return matches; 4093 }; 4094 /** 4095 * Parses the input `text` looking for URLs, email addresses, phone 4096 * numbers, username handles, and hashtags (depending on the configuration 4097 * of the Autolinker instance), and returns an array of {@link Autolinker.match.Match} 4098 * objects describing those matches. 4099 * 4100 * This method processes a **non-HTML string**, and is used to parse and 4101 * match within the text nodes of an HTML string. This method is used 4102 * internally by {@link #parse}. 4103 * 4104 * @private 4105 * @param {String} text The text to find matches within (depending on if the 4106 * {@link #urls}, {@link #email}, {@link #phone}, 4107 * {@link #hashtag}, and {@link #mention} options are enabled). This must be a non-HTML string. 4108 * @param {Number} [offset=0] The offset of the text node within the 4109 * original string. This is used when parsing with the {@link #parse} 4110 * method to generate correct offsets within the {@link Autolinker.match.Match} 4111 * instances, but may be omitted if calling this method publicly. 4112 * @return {Autolinker.match.Match[]} The array of Matches found in the 4113 * given input `text`. 4114 */ 4115 Autolinker.prototype.parseText = function (text, offset) { 4116 if (offset === void 0) { offset = 0; } 4117 offset = offset || 0; 4118 var matchers = this.getMatchers(), matches = []; 4119 for (var i = 0, numMatchers = matchers.length; i < numMatchers; i++) { 4120 var textMatches = matchers[i].parseMatches(text); 4121 // Correct the offset of each of the matches. They are originally 4122 // the offset of the match within the provided text node, but we 4123 // need to correct them to be relative to the original HTML input 4124 // string (i.e. the one provided to #parse). 4125 for (var j = 0, numTextMatches = textMatches.length; j < numTextMatches; j++) { 4126 textMatches[j].setOffset(offset + textMatches[j].getOffset()); 4127 } 4128 matches.push.apply(matches, textMatches); 4129 } 4130 return matches; 4131 }; 4132 /** 4133 * Automatically links URLs, Email addresses, Phone numbers, Hashtags, 4134 * and Mentions (Twitter, Instagram, Soundcloud) found in the given chunk of HTML. Does not link
4135 * URLs found within HTML tags. 4136 * 4137 * For instance, if given the text: `You should go to http://www.yahoo.com`, 4138 * then the result will be `You should go to 4139 * <a href="http://www.yahoo.com">http://www.yahoo.com</a>` 4140 * 4141 * This method finds the text around any HTML elements in the input 4142 * `textOrHtml`, which will be the text that is processed. Any original HTML 4143 * elements will be left as-is, as well as the text that is already wrapped 4144 * in anchor (<a>) tags. 4145 * 4146 * @param {String} textOrHtml The HTML or text to autolink matches within 4147 * (depending on if the {@link #urls}, {@link #email}, {@link #phone}, {@link #hashtag}, and {@link #mention} options are enabled). 4148 * @return {String} The HTML, with matches automatically linked. 4149 */ 4150 Autolinker.prototype.link = function (textOrHtml) { 4151 if (!textOrHtml) { 4152 return ""; 4153 } // handle `null` and `undefined` (for JavaScript users that don't have TypeScript support) 4154 /* We would want to sanitize the start and end characters of a tag 4155 * before processing the string in order to avoid an XSS scenario. 4156 * This behaviour can be changed by toggling the sanitizeHtml option. 4157 */ 4158 if (this.sanitizeHtml) { 4159 textOrHtml = textOrHtml 4160 .replace(/</g, '<') 4161 .replace(/>/g, '>'); 4162 } 4163 var matches = this.parse(textOrHtml), newHtml = [], lastIndex = 0; 4164 for (var i = 0, len = matches.length; i < len; i++) { 4165 var match = matches[i]; 4166 newHtml.push(textOrHtml.substring(lastIndex, match.getOffset())); 4167 newHtml.push(this.createMatchReturnVal(match)); 4168 lastIndex = match.getOffset() + match.getMatchedText().length; 4169 } 4170 newHtml.push(textOrHtml.substring(lastIndex)); // handle the text after the last match 4171 return newHtml.join(''); 4172 }; 4173 /** 4174 * Creates the return string value for a given match in the input string. 4175 * 4176 * This method handles the {@link #replaceFn}, if one was provided. 4177 * 4178 * @private 4179 * @param {Autolinker.match.Match} match The Match object that represents 4180 * the match. 4181 * @return {String} The string that the `match` should be replaced with. 4182 * This is usually the anchor tag string, but may be the `matchStr` itself 4183 * if the match is not to be replaced. 4184 */ 4185 Autolinker.prototype.createMatchReturnVal = function (match) { 4186 // Handle a custom `replaceFn` being provided 4187 var replaceFnResult; 4188 if (this.replaceFn) { 4189 replaceFnResult = this.replaceFn.call(this.context, match); // Autolinker instance is the context 4190 } 4191 if (typeof replaceFnResult === 'string') { 4192 return replaceFnResult; // `replaceFn` returned a string, use that 4193 } 4194 else if (replaceFnResult === false) { 4195 return match.getMatchedText(); // no replacement for the match 4196 } 4197 else if (replaceFnResult instanceof HtmlTag) { 4198 return replaceFnResult.toAnchorString(); 4199 } 4200 else { // replaceFnResult === true, or no/unknown return value from function 4201 // Perform Autolinker's default anchor tag generation 4202 var anchorTag = match.buildTag(); // returns an Autolinker.HtmlTag instance 4203 return anchorTag.toAnchorString(); 4204 } 4205 }; 4206 /** 4207 * Lazily instantiates and returns the {@link Autolinker.matcher.Matcher} 4208 * instances for this Autolinker instance. 4209 * 4210 * @private 4211 * @return {Autolinker.matcher.Matcher[]} 4212 */ 4213 Autolinker.prototype.getMatchers = function () { 4214 if (!this.matchers) { 4215 var tagBuilder = this.getTagBuilder(); 4216 var matchers = [ 4217 new HashtagMatcher({ tagBuilder: tagBuilder, serviceName: this.hashtag }), 4218 new EmailMatcher({ tagBuilder: tagBuilder }), 4219 new PhoneMatcher({ tagBuilder: tagBuilder }), 4220 new MentionMatcher({ tagBuilder: tagBuilder, serviceName: this.mention }), 4221 new UrlMatcher({ tagBuilder: tagBuilder, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash, decodePercentEncoding: this.decodePercentEncoding }) 4222 ]; 4223 return (this.matchers = matchers); 4224 } 4225 else { 4226 return this.matchers; 4227 } 4228 }; 4229 /** 4230 * Returns the {@link #tagBuilder} instance for this Autolinker instance, 4231 * lazily instantiating it if it does not yet exist. 4232 * 4233 * @private 4234 * @return {Autolinker.AnchorTagBuilder} 4235 */ 4236 Autolinker.prototype.getTagBuilder = function () { 4237 var tagBuilder = this.tagBuilder; 4238 if (!tagBuilder) { 4239 tagBuilder = this.tagBuilder = new AnchorTagBuilder({ 4240 newWindow: this.newWindow, 4241 truncate: this.truncate, 4242 className: this.className 4243 }); 4244 } 4245 return tagBuilder; 4246 }; 4247 /** 4248 * @static 4249 * @property {String} version 4250 * 4251 * The Autolinker version number in the form major.minor.patch 4252 * 4253 * Ex: 0.25.1 4254 */ 4255 Autolinker.version = '3.14.3'; 4256 /** 4257 * For backwards compatibility with Autolinker 1.x, the AnchorTagBuilder 4258 * class is provided as a static on the Autolinker class. 4259 */ 4260 Autolinker.AnchorTagBuilder = AnchorTagBuilder; 4261 /** 4262 * For backwards compatibility with Autolinker 1.x, the HtmlTag class is 4263 * provided as a static on the Autolinker class. 4264 */ 4265 Autolinker.HtmlTag = HtmlTag; 4266 /** 4267 * For backwards compatibility with Autolinker 1.x, the Matcher classes are 4268 * provided as statics on the Autolinker class. 4269 */ 4270 Autolinker.matcher = { 4271 Email: EmailMatcher, 4272 Hashtag: HashtagMatcher, 4273 Matcher: Matcher, 4274 Mention: MentionMatcher, 4275 Phone: PhoneMatcher, 4276 Url: UrlMatcher 4277 }; 4278 /** 4279 * For backwards compatibility with Autolinker 1.x, the Match classes are 4280 * provided as statics on the Autolinker class. 4281 */ 4282 Autolinker.match = { 4283 Email: EmailMatch, 4284 Hashtag: HashtagMatch, 4285 Match: Match, 4286 Mention: MentionMatch, 4287 Phone: PhoneMatch, 4288 Url: UrlMatch 4289 }; 4290 return Autolinker; 4291 }()); 4292 4293 return Autolinker; 4294 4295})); 4296 4297 4298//# sourceMappingURL=Autolinker.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.