|
406 | 406 | * Note: this is lazily instantiated in the {@link #getTagBuilder} method.
|
407 | 407 | */
|
408 | 408 | this.tagBuilder = null;
|
| 409 | + // Note: when `this.something` is used in the rhs of these assignments, |
| 410 | + // it refers to the default values set above the constructor |
409 | 411 | this.urls = this.normalizeUrlsCfg(cfg.urls);
|
410 |
| - this.email = typeof cfg.email === 'boolean' ? cfg.email : true; |
411 |
| - this.phone = typeof cfg.phone === 'boolean' ? cfg.phone : true; |
412 |
| - this.hashtag = cfg.hashtag || false; |
413 |
| - this.mention = cfg.mention || false; |
414 |
| - this.newWindow = typeof cfg.newWindow === 'boolean' ? cfg.newWindow : true; |
| 412 | + this.email = typeof cfg.email === 'boolean' ? cfg.email : this.email; |
| 413 | + this.phone = typeof cfg.phone === 'boolean' ? cfg.phone : this.phone; |
| 414 | + this.hashtag = cfg.hashtag || this.hashtag; |
| 415 | + this.mention = cfg.mention || this.mention; |
| 416 | + this.newWindow = typeof cfg.newWindow === 'boolean' ? cfg.newWindow : this.newWindow; |
415 | 417 | this.stripPrefix = this.normalizeStripPrefixCfg(cfg.stripPrefix);
|
416 |
| - this.stripTrailingSlash = typeof cfg.stripTrailingSlash === 'boolean' ? cfg.stripTrailingSlash : true; |
417 |
| - this.decodePercentEncoding = typeof cfg.decodePercentEncoding === 'boolean' ? cfg.decodePercentEncoding : true; |
| 418 | + this.stripTrailingSlash = typeof cfg.stripTrailingSlash === 'boolean' ? cfg.stripTrailingSlash : this.stripTrailingSlash; |
| 419 | + this.decodePercentEncoding = typeof cfg.decodePercentEncoding === 'boolean' ? cfg.decodePercentEncoding : this.decodePercentEncoding; |
418 | 420 | // Validate the value of the `mention` cfg
|
419 | 421 | var mention = this.mention;
|
420 | 422 | if (mention !== false && mention !== 'twitter' && mention !== 'instagram' && mention !== 'soundcloud') {
|
|
426 | 428 | throw new Error("invalid `hashtag` cfg - see docs");
|
427 | 429 | }
|
428 | 430 | this.truncate = this.normalizeTruncateCfg(cfg.truncate);
|
429 |
| - this.className = cfg.className || ''; |
430 |
| - this.replaceFn = cfg.replaceFn || null; |
| 431 | + this.className = cfg.className || this.className; |
| 432 | + this.replaceFn = cfg.replaceFn || this.replaceFn; |
431 | 433 | this.context = cfg.context || this;
|
432 | 434 | }
|
433 | 435 | <span id='Autolinker-static-method-link'> /**
|
|
593 | 595 | * given input `textOrHtml`.
|
594 | 596 | */
|
595 | 597 | Autolinker.prototype.parse = function (textOrHtml) {
|
596 |
| - var htmlNodes = this.htmlParser.parse(textOrHtml), anchorTagStackCount = 0, // used to only process text around anchor tags, and any inner text/html they may have; |
| 598 | + var htmlNodes = this.htmlParser.parse(textOrHtml), 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 |
597 | 599 | matches = [];
|
598 | 600 | // Find all matches within the `textOrHtml` (but not matches that are
|
599 | 601 | // already nested within <a>, <style> and <script> tags)
|
600 | 602 | for (var i = 0, len = htmlNodes.length; i < len; i++) {
|
601 | 603 | var node = htmlNodes[i], nodeType = node.getType();
|
602 |
| - if (nodeType === 'element' && ['a', 'style', 'script'].indexOf(node.getTagName()) !== -1) { // Process HTML anchor, style and script element nodes in the input `textOrHtml` to find out when we're within an <a>, <style> or <script> tag |
| 604 | + if (nodeType === 'element' && skipTagNames.indexOf(node.getTagName()) !== -1) { // Process HTML anchor, style and script element nodes in the input `textOrHtml` to find out when we're within an <a>, <style> or <script> tag |
603 | 605 | if (!node.isClosing()) { // it's the start <a>, <style> or <script> tag
|
604 |
| - anchorTagStackCount++; |
| 606 | + skipTagsStackCount++; |
605 | 607 | }
|
606 | 608 | else { // it's the end </a>, </style> or </script> tag
|
607 |
| - anchorTagStackCount = Math.max(anchorTagStackCount - 1, 0); // attempt to handle extraneous </a> tags by making sure the stack count never goes below 0 |
| 609 | + skipTagsStackCount = Math.max(skipTagsStackCount - 1, 0); // attempt to handle extraneous </a> tags by making sure the stack count never goes below 0 |
608 | 610 | }
|
609 | 611 | }
|
610 |
| - else if (nodeType === 'text' && anchorTagStackCount === 0) { // Process text nodes that are not within an <a>, <style> and <script> tag |
| 612 | + else if (nodeType === 'text' && skipTagsStackCount === 0) { // Process text nodes that are not within an <a>, <style> and <script> tag |
611 | 613 | var textNodeMatches = this.parseText(node.getText(), node.getOffset());
|
612 | 614 | matches.push.apply(matches, textNodeMatches);
|
613 | 615 | }
|
|
844 | 846 | *
|
845 | 847 | * Ex: 0.25.1
|
846 | 848 | */
|
847 |
| - Autolinker.version = '1.8.3'; |
| 849 | + Autolinker.version = '2.0.0'; |
848 | 850 | <span id='Autolinker-AnchorTagBuilder'> /**
|
849 | 851 | </span> * For backwards compatibility with Autolinker 1.x, the AnchorTagBuilder
|
850 | 852 | * class is provided as a static on the Autolinker class.
|
|
0 commit comments