22/**
33 * @class Autolinker.match.Url
44 * @extends Autolinker.match.Match
5- *
5+ *
66 * Represents a Url match found in an input string which should be Autolinked.
7- *
7+ *
88 * See this class's superclass ({@link Autolinker.match.Match}) for more details.
99 */
1010Autolinker . match . Url = Autolinker . Util . extend ( Autolinker . match . Match , {
11-
11+
1212 /**
1313 * @cfg {String} url (required)
14- *
14+ *
1515 * The url that was matched.
1616 */
17-
17+
1818 /**
1919 * @cfg {Boolean} protocolUrlMatch (required)
20- *
20+ *
2121 * `true` if the URL is a match which already has a protocol (i.e. 'http://'), `false` if the match was from a 'www' or
2222 * known TLD match.
2323 */
24-
24+
2525 /**
2626 * @cfg {Boolean} protocolRelativeMatch (required)
27- *
27+ *
2828 * `true` if the URL is a protocol-relative match. A protocol-relative match is a URL that starts with '//',
2929 * and will be either http:// or https:// based on the protocol that the site is loaded under.
3030 */
31-
31+
3232 /**
3333 * @cfg {Boolean} stripPrefix (required)
3434 * @inheritdoc Autolinker#stripPrefix
3535 */
36-
36+
3737
3838 /**
3939 * @private
4040 * @property {RegExp } urlPrefixRegex
41- *
41+ *
4242 * A regular expression used to remove the 'http://' or 'https://' and/or the 'www.' from URLs.
4343 */
4444 urlPrefixRegex : / ^ ( h t t p s ? : \/ \/ ) ? ( w w w \. ) ? / i,
45-
45+
4646 /**
4747 * @private
4848 * @property {RegExp } protocolRelativeRegex
49- *
49+ *
5050 * The regular expression used to remove the protocol-relative '//' from the {@link #url} string, for purposes
5151 * of {@link #getAnchorText}. A protocol-relative URL is, for example, "//yahoo.com"
5252 */
5353 protocolRelativeRegex : / ^ \/ \/ / ,
54-
54+
5555 /**
5656 * @private
5757 * @property {Boolean } protocolPrepended
58- *
58+ *
5959 * Will be set to `true` if the 'http://' protocol has been prepended to the {@link #url} (because the
6060 * {@link #url} did not have a protocol)
6161 */
6262 protocolPrepended : false ,
63-
63+
6464
6565 /**
6666 * Returns a string name for the type of match that this class represents.
67- *
67+ *
6868 * @return {String }
6969 */
7070 getType : function ( ) {
7171 return 'url' ;
7272 } ,
73-
74-
73+
74+
7575 /**
7676 * Returns the url that was matched, assuming the protocol to be 'http://' if the original
7777 * match was missing a protocol.
78- *
78+ *
7979 * @return {String }
8080 */
8181 getUrl : function ( ) {
8282 var url = this . url ;
83-
83+
8484 // if the url string doesn't begin with a protocol, assume 'http://'
8585 if ( ! this . protocolRelativeMatch && ! this . protocolUrlMatch && ! this . protocolPrepended ) {
8686 url = this . url = 'http://' + url ;
87-
87+
8888 this . protocolPrepended = true ;
8989 }
90-
90+
9191 return url ;
9292 } ,
93-
93+
9494
9595 /**
9696 * Returns the anchor href that should be generated for the match.
97- *
97+ *
9898 * @return {String }
9999 */
100100 getAnchorHref : function ( ) {
101101 var url = this . getUrl ( ) ;
102-
103- return url . replace ( / & a m p ; / g, '&' ) ; // any &'s in the URL should be converted back to '&' if they were displayed as & in the source html
102+
103+ return url . replace ( / & a m p ; / g, '&' ) ; // any &'s in the URL should be converted back to '&' if they were displayed as & in the source html
104104 } ,
105-
106-
105+
106+
107107 /**
108108 * Returns the anchor text that should be generated for the match.
109- *
109+ *
110110 * @return {String }
111111 */
112112 getAnchorText : function ( ) {
113- var anchorText = this . getUrl ( ) ;
114-
113+ var anchorText = this . getMatchedText ( ) ;
114+
115115 if ( this . protocolRelativeMatch ) {
116116 // Strip off any protocol-relative '//' from the anchor text
117117 anchorText = this . stripProtocolRelativePrefix ( anchorText ) ;
@@ -120,18 +120,18 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
120120 anchorText = this . stripUrlPrefix ( anchorText ) ;
121121 }
122122 anchorText = this . removeTrailingSlash ( anchorText ) ; // remove trailing slash, if there is one
123-
123+
124124 return anchorText ;
125125 } ,
126-
127-
126+
127+
128128 // ---------------------------------------
129-
129+
130130 // Utility Functionality
131-
131+
132132 /**
133133 * Strips the URL prefix (such as "http://" or "https://") from the given text.
134- *
134+ *
135135 * @private
136136 * @param {String } text The text of the anchor that is being generated, for which to strip off the
137137 * url prefix (such as stripping off "http://")
@@ -140,11 +140,11 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
140140 stripUrlPrefix : function ( text ) {
141141 return text . replace ( this . urlPrefixRegex , '' ) ;
142142 } ,
143-
144-
143+
144+
145145 /**
146146 * Strips any protocol-relative '//' from the anchor text.
147- *
147+ *
148148 * @private
149149 * @param {String } text The text of the anchor that is being generated, for which to strip off the
150150 * protocol-relative prefix (such as stripping off "//")
@@ -153,11 +153,11 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
153153 stripProtocolRelativePrefix : function ( text ) {
154154 return text . replace ( this . protocolRelativeRegex , '' ) ;
155155 } ,
156-
157-
156+
157+
158158 /**
159159 * Removes any trailing slash from the given `anchorText`, in preparation for the text to be displayed.
160- *
160+ *
161161 * @private
162162 * @param {String } anchorText The text of the anchor that is being generated, for which to remove any trailing
163163 * slash ('/') that may exist.
@@ -169,5 +169,5 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
169169 }
170170 return anchorText ;
171171 }
172-
172+
173173} ) ;
0 commit comments