|
269 | 269 | * `'www.google.com'` will be displayed as `'google.com'`. `false` to not
|
270 | 270 | * strip the `'www'`.
|
271 | 271 | */
|
272 |
| - this.stripPrefix = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 272 | + this.stripPrefix = { |
| 273 | + scheme: true, |
| 274 | + www: true, |
| 275 | + }; // default value just to get the above doc comment in the ES5 output and documentation generator |
273 | 276 | <span id='Autolinker-cfg-stripTrailingSlash'> /**
|
274 | 277 | </span> * @cfg {Boolean} [stripTrailingSlash=true]
|
275 | 278 | *
|
|
337 | 340 | * 'yahoo.com/some..to/a/file'. For more details, see
|
338 | 341 | * {@link Autolinker.truncate.TruncateSmart}.
|
339 | 342 | */
|
340 |
| - this.truncate = { length: 0, location: 'end' }; // default value just to get the above doc comment in the ES5 output and documentation generator |
| 343 | + this.truncate = { |
| 344 | + length: 0, |
| 345 | + location: 'end', |
| 346 | + }; // default value just to get the above doc comment in the ES5 output and documentation generator |
341 | 347 | <span id='Autolinker-cfg-className'> /**
|
342 | 348 | </span> * @cfg {String} className
|
343 | 349 | *
|
|
423 | 429 | this.mention = cfg.mention || this.mention;
|
424 | 430 | this.newWindow = typeof cfg.newWindow === 'boolean' ? cfg.newWindow : this.newWindow;
|
425 | 431 | this.stripPrefix = this.normalizeStripPrefixCfg(cfg.stripPrefix);
|
426 |
| - this.stripTrailingSlash = typeof cfg.stripTrailingSlash === 'boolean' ? cfg.stripTrailingSlash : this.stripTrailingSlash; |
427 |
| - this.decodePercentEncoding = typeof cfg.decodePercentEncoding === 'boolean' ? cfg.decodePercentEncoding : this.decodePercentEncoding; |
| 432 | + this.stripTrailingSlash = |
| 433 | + typeof cfg.stripTrailingSlash === 'boolean' |
| 434 | + ? cfg.stripTrailingSlash |
| 435 | + : this.stripTrailingSlash; |
| 436 | + this.decodePercentEncoding = |
| 437 | + typeof cfg.decodePercentEncoding === 'boolean' |
| 438 | + ? cfg.decodePercentEncoding |
| 439 | + : this.decodePercentEncoding; |
428 | 440 | this.sanitizeHtml = cfg.sanitizeHtml || false;
|
429 | 441 | // Validate the value of the `mention` cfg
|
430 | 442 | var mention = this.mention;
|
431 |
| - if (mention !== false && ['twitter', 'instagram', 'soundcloud', 'tiktok'].indexOf(mention) === -1) { |
| 443 | + if (mention !== false && |
| 444 | + ['twitter', 'instagram', 'soundcloud', 'tiktok'].indexOf(mention) === -1) { |
432 | 445 | throw new Error("invalid `mention` cfg '".concat(mention, "' - see docs"));
|
433 | 446 | }
|
434 | 447 | // Validate the value of the `hashtag` cfg
|
435 | 448 | var hashtag = this.hashtag;
|
436 |
| - if (hashtag !== false && ['twitter', 'facebook', 'instagram', 'tiktok'].indexOf(hashtag) === -1) { |
| 449 | + if (hashtag !== false && |
| 450 | + ['twitter', 'facebook', 'instagram', 'tiktok'].indexOf(hashtag) === -1) { |
437 | 451 | throw new Error("invalid `hashtag` cfg '".concat(hashtag, "' - see docs"));
|
438 | 452 | }
|
439 | 453 | this.truncate = this.normalizeTruncateCfg(cfg.truncate);
|
|
520 | 534 | if (typeof urls === 'boolean') {
|
521 | 535 | return { schemeMatches: urls, wwwMatches: urls, tldMatches: urls };
|
522 | 536 | }
|
523 |
| - else { // object form |
| 537 | + else { |
| 538 | + // object form |
524 | 539 | return {
|
525 | 540 | schemeMatches: typeof urls.schemeMatches === 'boolean' ? urls.schemeMatches : true,
|
526 | 541 | wwwMatches: typeof urls.wwwMatches === 'boolean' ? urls.wwwMatches : true,
|
527 |
| - tldMatches: typeof urls.tldMatches === 'boolean' ? urls.tldMatches : true |
| 542 | + tldMatches: typeof urls.tldMatches === 'boolean' ? urls.tldMatches : true, |
528 | 543 | };
|
529 | 544 | }
|
530 | 545 | };
|
|
544 | 559 | if (typeof stripPrefix === 'boolean') {
|
545 | 560 | return { scheme: stripPrefix, www: stripPrefix };
|
546 | 561 | }
|
547 |
| - else { // object form |
| 562 | + else { |
| 563 | + // object form |
548 | 564 | return {
|
549 | 565 | scheme: typeof stripPrefix.scheme === 'boolean' ? stripPrefix.scheme : true,
|
550 |
| - www: typeof stripPrefix.www === 'boolean' ? stripPrefix.www : true |
| 566 | + www: typeof stripPrefix.www === 'boolean' ? stripPrefix.www : true, |
551 | 567 | };
|
552 | 568 | }
|
553 | 569 | };
|
|
565 | 581 | if (typeof truncate === 'number') {
|
566 | 582 | return { length: truncate, location: 'end' };
|
567 | 583 | }
|
568 |
| - else { // object, or undefined/null |
| 584 | + else { |
| 585 | + // object, or undefined/null |
569 | 586 | return (0, utils_1.defaults)(truncate || {}, {
|
570 | 587 | length: Number.POSITIVE_INFINITY,
|
571 |
| - location: 'end' |
| 588 | + location: 'end', |
572 | 589 | });
|
573 | 590 | }
|
574 | 591 | };
|
|
619 | 636 | // Only process text nodes that are not within an <a>, <style> or <script> tag
|
620 | 637 | if (skipTagsStackCount === 0) {
|
621 | 638 | // "Walk around" common HTML entities. An '&nbsp;' (for example)
|
622 |
| - // could be at the end of a URL, but we don't want to |
| 639 | + // could be at the end of a URL, but we don't want to |
623 | 640 | // include the trailing '&' in the URL. See issue #76
|
624 | 641 | // TODO: Handle HTML entities separately in parseHtml() and
|
625 | 642 | // don't emit them as "text" except for &amp; entities
|
|
668 | 685 | */
|
669 | 686 | Autolinker.prototype.compactMatches = function (matches) {
|
670 | 687 | // First, the matches need to be sorted in order of offset
|
671 |
| - matches.sort(function (a, b) { return a.getOffset() - b.getOffset(); }); |
| 688 | + matches.sort(function (a, b) { |
| 689 | + return a.getOffset() - b.getOffset(); |
| 690 | + }); |
672 | 691 | var i = 0;
|
673 | 692 | while (i < matches.length - 1) {
|
674 | 693 | var match = matches[i], offset = match.getOffset(), matchedTextLength = match.getMatchedText().length, endIdx = offset + matchedTextLength;
|
|
709 | 728 | */
|
710 | 729 | Autolinker.prototype.removeUnwantedMatches = function (matches) {
|
711 | 730 | if (!this.hashtag)
|
712 |
| - (0, utils_1.remove)(matches, function (match) { return match.getType() === 'hashtag'; }); |
| 731 | + (0, utils_1.remove)(matches, function (match) { |
| 732 | + return match.getType() === 'hashtag'; |
| 733 | + }); |
713 | 734 | if (!this.email)
|
714 |
| - (0, utils_1.remove)(matches, function (match) { return match.getType() === 'email'; }); |
| 735 | + (0, utils_1.remove)(matches, function (match) { |
| 736 | + return match.getType() === 'email'; |
| 737 | + }); |
715 | 738 | if (!this.phone)
|
716 |
| - (0, utils_1.remove)(matches, function (match) { return match.getType() === 'phone'; }); |
| 739 | + (0, utils_1.remove)(matches, function (match) { |
| 740 | + return match.getType() === 'phone'; |
| 741 | + }); |
717 | 742 | if (!this.mention)
|
718 |
| - (0, utils_1.remove)(matches, function (match) { return match.getType() === 'mention'; }); |
| 743 | + (0, utils_1.remove)(matches, function (match) { |
| 744 | + return match.getType() === 'mention'; |
| 745 | + }); |
719 | 746 | if (!this.urls.schemeMatches) {
|
720 |
| - (0, utils_1.remove)(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'scheme'; }); |
| 747 | + (0, utils_1.remove)(matches, function (m) { |
| 748 | + return m.getType() === 'url' && m.getUrlMatchType() === 'scheme'; |
| 749 | + }); |
721 | 750 | }
|
722 | 751 | if (!this.urls.wwwMatches) {
|
723 | 752 | (0, utils_1.remove)(matches, function (m) { return m.getType() === 'url' && m.getUrlMatchType() === 'www'; });
|
|
785 | 814 | */
|
786 | 815 | Autolinker.prototype.link = function (textOrHtml) {
|
787 | 816 | if (!textOrHtml) {
|
788 |
| - return ""; |
| 817 | + return ''; |
789 | 818 | } // handle `null` and `undefined` (for JavaScript users that don't have TypeScript support)
|
790 | 819 | /* We would want to sanitize the start and end characters of a tag
|
791 | 820 | * before processing the string in order to avoid an XSS scenario.
|
792 | 821 | * This behaviour can be changed by toggling the sanitizeHtml option.
|
793 | 822 | */
|
794 | 823 | if (this.sanitizeHtml) {
|
795 |
| - textOrHtml = textOrHtml |
796 |
| - .replace(/</g, '&lt;') |
797 |
| - .replace(/>/g, '&gt;'); |
| 824 | + textOrHtml = textOrHtml.replace(/</g, '&lt;').replace(/>/g, '&gt;'); |
798 | 825 | }
|
799 | 826 | var matches = this.parse(textOrHtml), newHtml = [], lastIndex = 0;
|
800 | 827 | for (var i = 0, len = matches.length; i < len; i++) {
|
|
833 | 860 | else if (replaceFnResult instanceof html_tag_1.HtmlTag) {
|
834 | 861 | return replaceFnResult.toAnchorString();
|
835 | 862 | }
|
836 |
| - else { // replaceFnResult === true, or no/unknown return value from function |
| 863 | + else { |
| 864 | + // replaceFnResult === true, or no/unknown return value from function |
837 | 865 | // Perform Autolinker's default anchor tag generation
|
838 | 866 | var anchorTag = match.buildTag(); // returns an Autolinker.HtmlTag instance
|
839 | 867 | return anchorTag.toAnchorString();
|
|
850 | 878 | if (!this.matchers) {
|
851 | 879 | var tagBuilder = this.getTagBuilder();
|
852 | 880 | var matchers = [
|
853 |
| - new hashtag_matcher_1.HashtagMatcher({ tagBuilder: tagBuilder, serviceName: this.hashtag }), |
| 881 | + new hashtag_matcher_1.HashtagMatcher({ |
| 882 | + tagBuilder: tagBuilder, |
| 883 | + serviceName: this.hashtag, |
| 884 | + }), |
854 | 885 | new email_matcher_1.EmailMatcher({ tagBuilder: tagBuilder }),
|
855 | 886 | new phone_matcher_1.PhoneMatcher({ tagBuilder: tagBuilder }),
|
856 |
| - new mention_matcher_1.MentionMatcher({ tagBuilder: tagBuilder, serviceName: this.mention }), |
857 |
| - new url_matcher_1.UrlMatcher({ tagBuilder: tagBuilder, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash, decodePercentEncoding: this.decodePercentEncoding }) |
| 887 | + new mention_matcher_1.MentionMatcher({ |
| 888 | + tagBuilder: tagBuilder, |
| 889 | + serviceName: this.mention, |
| 890 | + }), |
| 891 | + new url_matcher_1.UrlMatcher({ |
| 892 | + tagBuilder: tagBuilder, |
| 893 | + stripPrefix: this.stripPrefix, |
| 894 | + stripTrailingSlash: this.stripTrailingSlash, |
| 895 | + decodePercentEncoding: this.decodePercentEncoding, |
| 896 | + }), |
858 | 897 | ];
|
859 | 898 | return (this.matchers = matchers);
|
860 | 899 | }
|
|
875 | 914 | tagBuilder = this.tagBuilder = new anchor_tag_builder_1.AnchorTagBuilder({
|
876 | 915 | newWindow: this.newWindow,
|
877 | 916 | truncate: this.truncate,
|
878 |
| - className: this.className |
| 917 | + className: this.className, |
879 | 918 | });
|
880 | 919 | }
|
881 | 920 | return tagBuilder;
|
882 | 921 | };
|
| 922 | + // NOTE: must be 'export default' here for UMD module |
883 | 923 | <span id='Autolinker-static-property-version'> /**
|
884 | 924 | </span> * @static
|
885 | 925 | * @property {String} version
|
|
909 | 949 | Matcher: matcher_1.Matcher,
|
910 | 950 | Mention: mention_matcher_1.MentionMatcher,
|
911 | 951 | Phone: phone_matcher_1.PhoneMatcher,
|
912 |
| - Url: url_matcher_1.UrlMatcher |
| 952 | + Url: url_matcher_1.UrlMatcher, |
913 | 953 | };
|
914 | 954 | <span id='Autolinker-HtmlTag-property-match'> /**
|
915 | 955 | </span> * For backwards compatibility with Autolinker 1.x, the Match classes are
|
|
921 | 961 | Match: match_1.Match,
|
922 | 962 | Mention: mention_match_1.MentionMatch,
|
923 | 963 | Phone: phone_match_1.PhoneMatch,
|
924 |
| - Url: url_match_1.UrlMatch |
| 964 | + Url: url_match_1.UrlMatch, |
925 | 965 | };
|
926 | 966 | return Autolinker;
|
927 | 967 | }());
|
|
0 commit comments