Skip to content

Commit b5d8e50

Browse files
committed
Build 0.21.0
1 parent 2f0e438 commit b5d8e50

File tree

3 files changed

+72
-60
lines changed

3 files changed

+72
-60
lines changed

dist/Autolinker.js

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/*!
1818
* Autolinker.js
19-
* 0.20.0
19+
* 0.21.0
2020
*
2121
* Copyright(c) 2015 Gregory Jacobs <[email protected]>
2222
* MIT
@@ -1772,17 +1772,18 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
17721772
* 8. A protocol-relative ('//') match for the case of a known TLD prefixed
17731773
* URL. Will be an empty string if it is not a protocol-relative match.
17741774
* See #6 for more info.
1775-
* 9. Group that is used to determine if there is a phone number match. The
1776-
* next 3 groups give segments of the phone number.
1777-
* 10. Group that is used to determine if there is a Hashtag match
1775+
* 9. Group that is used to determine if there is a phone number match.
1776+
* 10. If there is a phone number match, and a '+' sign was included with
1777+
* the phone number, this group will be populated with the '+' sign.
1778+
* 11. Group that is used to determine if there is a Hashtag match
17781779
* (i.e. \#someHashtag). Simply check for its existence to determine if
17791780
* there is a Hashtag match. The next couple of capturing groups give
17801781
* information about the Hashtag match.
1781-
* 11. The whitespace character before the #sign in a Hashtag handle. This
1782+
* 12. The whitespace character before the #sign in a Hashtag handle. This
17821783
* is needed because there are no look-behinds in JS regular
17831784
* expressions, and can be used to reconstruct the original string in a
17841785
* replace().
1785-
* 12. The Hashtag itself in a Hashtag match. If the match is
1786+
* 13. The Hashtag itself in a Hashtag match. If the match is
17861787
* '#someHashtag', the hashtag is 'someHashtag'.
17871788
*/
17881789
matcherRegex : (function() {
@@ -1791,7 +1792,7 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
17911792
hashtagRegex = /(^|[^\w])#(\w{1,139})/, // For matching a Hashtag. Ex: #games
17921793

17931794
emailRegex = /(?:[\-;:&=\+\$,\w\.]+@)/, // something@ for email addresses (a.k.a. local-part)
1794-
phoneRegex = /(?:\+?\d{1,3}[-\040.])?\(?\d{3}\)?[-\040.]?\d{3}[-\040.]\d{4}/, // ex: (123) 456-7890, 123 456 7890, 123-456-7890, etc.
1795+
phoneRegex = /(?:(\+)?\d{1,3}[-\040.])?\(?\d{3}\)?[-\040.]?\d{3}[-\040.]\d{4}/, // ex: (123) 456-7890, 123 456 7890, 123-456-7890, etc.
17951796
protocolRegex = /(?:[A-Za-z][-.+A-Za-z0-9]*:(?![A-Za-z][-.+A-Za-z0-9]*:\/\/)(?!\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)
17961797
wwwRegex = /(?:www\.)/, // starting with 'www.'
17971798
domainNameRegex = /[A-Za-z0-9\.\-]*[A-Za-z0-9\-]/, // anything looking at all like a domain, non-unicode domains, not ending in a period
@@ -1914,8 +1915,8 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
19141915
replace : function( text, replaceFn, contextObj ) {
19151916
var me = this; // for closure
19161917

1917-
return text.replace( this.matcherRegex, function( matchStr, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 ) {
1918-
var matchDescObj = me.processCandidateMatch( matchStr, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 ); // "match description" object
1918+
return text.replace( this.matcherRegex, function( matchStr, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13 ) {
1919+
var matchDescObj = me.processCandidateMatch( matchStr, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13 ); // "match description" object
19191920

19201921
// Return out with no changes for match types that are disabled (url,
19211922
// email, phone, etc.), or for matches that are invalid (false
@@ -1965,6 +1966,8 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
19651966
* match from a TLD (top level domain) match, with the character that
19661967
* comes before the '//'.
19671968
* @param {String} phoneMatch The matched text of a phone number
1969+
* @param {String} phonePlusSignMatch The '+' sign in the phone number, if
1970+
* it was there.
19681971
* @param {String} hashtagMatch The matched text of a Twitter
19691972
* Hashtag, if the match is a Hashtag match.
19701973
* @param {String} hashtagPrefixWhitespaceChar The whitespace char
@@ -1991,7 +1994,7 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
19911994
processCandidateMatch : function(
19921995
matchStr, twitterMatch, twitterHandlePrefixWhitespaceChar, twitterHandle,
19931996
emailAddressMatch, urlMatch, protocolUrlMatch, wwwProtocolRelativeMatch,
1994-
tldProtocolRelativeMatch, phoneMatch, hashtagMatch,
1997+
tldProtocolRelativeMatch, phoneMatch, phonePlusSignMatch, hashtagMatch,
19951998
hashtagPrefixWhitespaceChar, hashtag
19961999
) {
19972000
// Note: The `matchStr` variable wil be fixed up to remove characters that are no longer needed (which will
@@ -2049,7 +2052,7 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
20492052
} else if( phoneMatch ) {
20502053
// remove non-numeric values from phone number string
20512054
var cleanNumber = matchStr.replace( /\D/g, '' );
2052-
match = new Autolinker.match.Phone( { matchedText: matchStr, number: cleanNumber } );
2055+
match = new Autolinker.match.Phone( { matchedText: matchStr, number: cleanNumber, plusSign: !!phonePlusSignMatch } );
20532056

20542057
} else if( hashtagMatch ) {
20552058
// fix up the `matchStr` if there was a preceding whitespace char,
@@ -2611,6 +2614,15 @@ Autolinker.match.Phone = Autolinker.Util.extend( Autolinker.match.Match, {
26112614
* The phone number that was matched.
26122615
*/
26132616

2617+
/**
2618+
* @cfg {Boolean} plusSign (required)
2619+
*
2620+
* `true` if the matched phone number started with a '+' sign. We'll include
2621+
* it in the `tel:` URL if so, as this is needed for international numbers.
2622+
*
2623+
* Ex: '+1 (123) 456 7879'
2624+
*/
2625+
26142626

26152627
/**
26162628
* Returns a string name for the type of match that this class represents.
@@ -2638,7 +2650,7 @@ Autolinker.match.Phone = Autolinker.Util.extend( Autolinker.match.Match, {
26382650
* @return {String}
26392651
*/
26402652
getAnchorHref : function() {
2641-
return 'tel:' + this.number;
2653+
return 'tel:' + ( this.plusSign ? '+' : '' ) + this.number;
26422654
},
26432655

26442656

@@ -2715,116 +2727,116 @@ Autolinker.match.Twitter = Autolinker.Util.extend( Autolinker.match.Match, {
27152727
/**
27162728
* @class Autolinker.match.Url
27172729
* @extends Autolinker.match.Match
2718-
*
2730+
*
27192731
* Represents a Url match found in an input string which should be Autolinked.
2720-
*
2732+
*
27212733
* See this class's superclass ({@link Autolinker.match.Match}) for more details.
27222734
*/
27232735
Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
2724-
2736+
27252737
/**
27262738
* @cfg {String} url (required)
2727-
*
2739+
*
27282740
* The url that was matched.
27292741
*/
2730-
2742+
27312743
/**
27322744
* @cfg {Boolean} protocolUrlMatch (required)
2733-
*
2745+
*
27342746
* `true` if the URL is a match which already has a protocol (i.e. 'http://'), `false` if the match was from a 'www' or
27352747
* known TLD match.
27362748
*/
2737-
2749+
27382750
/**
27392751
* @cfg {Boolean} protocolRelativeMatch (required)
2740-
*
2752+
*
27412753
* `true` if the URL is a protocol-relative match. A protocol-relative match is a URL that starts with '//',
27422754
* and will be either http:// or https:// based on the protocol that the site is loaded under.
27432755
*/
2744-
2756+
27452757
/**
27462758
* @cfg {Boolean} stripPrefix (required)
27472759
* @inheritdoc Autolinker#stripPrefix
27482760
*/
2749-
2761+
27502762

27512763
/**
27522764
* @private
27532765
* @property {RegExp} urlPrefixRegex
2754-
*
2766+
*
27552767
* A regular expression used to remove the 'http://' or 'https://' and/or the 'www.' from URLs.
27562768
*/
27572769
urlPrefixRegex: /^(https?:\/\/)?(www\.)?/i,
2758-
2770+
27592771
/**
27602772
* @private
27612773
* @property {RegExp} protocolRelativeRegex
2762-
*
2774+
*
27632775
* The regular expression used to remove the protocol-relative '//' from the {@link #url} string, for purposes
27642776
* of {@link #getAnchorText}. A protocol-relative URL is, for example, "//yahoo.com"
27652777
*/
27662778
protocolRelativeRegex : /^\/\//,
2767-
2779+
27682780
/**
27692781
* @private
27702782
* @property {Boolean} protocolPrepended
2771-
*
2783+
*
27722784
* Will be set to `true` if the 'http://' protocol has been prepended to the {@link #url} (because the
27732785
* {@link #url} did not have a protocol)
27742786
*/
27752787
protocolPrepended : false,
2776-
2788+
27772789

27782790
/**
27792791
* Returns a string name for the type of match that this class represents.
2780-
*
2792+
*
27812793
* @return {String}
27822794
*/
27832795
getType : function() {
27842796
return 'url';
27852797
},
2786-
2787-
2798+
2799+
27882800
/**
27892801
* Returns the url that was matched, assuming the protocol to be 'http://' if the original
27902802
* match was missing a protocol.
2791-
*
2803+
*
27922804
* @return {String}
27932805
*/
27942806
getUrl : function() {
27952807
var url = this.url;
2796-
2808+
27972809
// if the url string doesn't begin with a protocol, assume 'http://'
27982810
if( !this.protocolRelativeMatch && !this.protocolUrlMatch && !this.protocolPrepended ) {
27992811
url = this.url = 'http://' + url;
2800-
2812+
28012813
this.protocolPrepended = true;
28022814
}
2803-
2815+
28042816
return url;
28052817
},
2806-
2818+
28072819

28082820
/**
28092821
* Returns the anchor href that should be generated for the match.
2810-
*
2822+
*
28112823
* @return {String}
28122824
*/
28132825
getAnchorHref : function() {
28142826
var url = this.getUrl();
2815-
2816-
return url.replace( /&amp;/g, '&' ); // any &amp;'s in the URL should be converted back to '&' if they were displayed as &amp; in the source html
2827+
2828+
return url.replace( /&amp;/g, '&' ); // any &amp;'s in the URL should be converted back to '&' if they were displayed as &amp; in the source html
28172829
},
2818-
2819-
2830+
2831+
28202832
/**
28212833
* Returns the anchor text that should be generated for the match.
2822-
*
2834+
*
28232835
* @return {String}
28242836
*/
28252837
getAnchorText : function() {
2826-
var anchorText = this.getUrl();
2827-
2838+
var anchorText = this.getMatchedText();
2839+
28282840
if( this.protocolRelativeMatch ) {
28292841
// Strip off any protocol-relative '//' from the anchor text
28302842
anchorText = this.stripProtocolRelativePrefix( anchorText );
@@ -2833,18 +2845,18 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
28332845
anchorText = this.stripUrlPrefix( anchorText );
28342846
}
28352847
anchorText = this.removeTrailingSlash( anchorText ); // remove trailing slash, if there is one
2836-
2848+
28372849
return anchorText;
28382850
},
2839-
2840-
2851+
2852+
28412853
// ---------------------------------------
2842-
2854+
28432855
// Utility Functionality
2844-
2856+
28452857
/**
28462858
* Strips the URL prefix (such as "http://" or "https://") from the given text.
2847-
*
2859+
*
28482860
* @private
28492861
* @param {String} text The text of the anchor that is being generated, for which to strip off the
28502862
* url prefix (such as stripping off "http://")
@@ -2853,11 +2865,11 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
28532865
stripUrlPrefix : function( text ) {
28542866
return text.replace( this.urlPrefixRegex, '' );
28552867
},
2856-
2857-
2868+
2869+
28582870
/**
28592871
* Strips any protocol-relative '//' from the anchor text.
2860-
*
2872+
*
28612873
* @private
28622874
* @param {String} text The text of the anchor that is being generated, for which to strip off the
28632875
* protocol-relative prefix (such as stripping off "//")
@@ -2866,11 +2878,11 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
28662878
stripProtocolRelativePrefix : function( text ) {
28672879
return text.replace( this.protocolRelativeRegex, '' );
28682880
},
2869-
2870-
2881+
2882+
28712883
/**
28722884
* Removes any trailing slash from the given `anchorText`, in preparation for the text to be displayed.
2873-
*
2885+
*
28742886
* @private
28752887
* @param {String} anchorText The text of the anchor that is being generated, for which to remove any trailing
28762888
* slash ('/') that may exist.
@@ -2882,7 +2894,7 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
28822894
}
28832895
return anchorText;
28842896
}
2885-
2897+
28862898
} );
28872899
/*global Autolinker */
28882900
/**

0 commit comments

Comments
 (0)