@@ -422,6 +422,33 @@ Autolinker.prototype = {
422422 } ,
423423
424424
425+ /**
426+ * After we have found all matches, we need to remove subsequent matches
427+ * that overlap with a previous match. This can happen for instance with
428+ * URLs, where the url 'google.com/#link' would match '#link' as a hashtag.
429+ *
430+ * @private
431+ * @param {Autolinker.match.Match[] } matches
432+ * @return {Autolinker.match.Match[] }
433+ */
434+ compactMatches : function ( matches ) {
435+ // First, the matches need to be sorted in order of offset
436+ matches . sort ( function ( a , b ) { return a . getOffset ( ) - b . getOffset ( ) ; } ) ;
437+
438+ for ( var i = 0 ; i < matches . length - 1 ; i ++ ) {
439+ var match = matches [ i ] ,
440+ endIdx = match . getOffset ( ) + match . getMatchedText ( ) . length ;
441+
442+ // Remove subsequent matches that overlap with the current match
443+ while ( i + 1 < matches . length && matches [ i + 1 ] . getOffset ( ) <= endIdx ) {
444+ matches . splice ( i + 1 , 1 ) ;
445+ }
446+ }
447+
448+ return matches ;
449+ } ,
450+
451+
425452 /**
426453 * Removes matches for matchers that were turned off in the options. For
427454 * example, if {@link #hashtag hashtags} were not to be matched, we'll
@@ -454,33 +481,6 @@ Autolinker.prototype = {
454481 } ,
455482
456483
457- /**
458- * After we have found all matches, we need to remove subsequent matches
459- * that overlap with a previous match. This can happen for instance with
460- * URLs, where the url 'google.com/#link' would match '#link' as a hashtag.
461- *
462- * @private
463- * @param {Autolinker.match.Match[] } matches
464- * @return {Autolinker.match.Match[] }
465- */
466- compactMatches : function ( matches ) {
467- // First, the matches need to be sorted in order of offset
468- matches . sort ( function ( a , b ) { return a . getOffset ( ) - b . getOffset ( ) ; } ) ;
469-
470- for ( var i = 0 ; i < matches . length - 1 ; i ++ ) {
471- var match = matches [ i ] ,
472- endIdx = match . getOffset ( ) + match . getMatchedText ( ) . length ;
473-
474- // Remove subsequent matches that overlap with the current match
475- while ( i + 1 < matches . length && matches [ i + 1 ] . getOffset ( ) <= endIdx ) {
476- matches . splice ( i + 1 , 1 ) ;
477- }
478- }
479-
480- return matches ;
481- } ,
482-
483-
484484 /**
485485 * Parses the input `text` looking for URLs, email addresses, phone
486486 * numbers, username handles, and hashtags (depending on the configuration
@@ -594,8 +594,7 @@ Autolinker.prototype = {
594594
595595 } else { // replaceFnResult === true, or no/unknown return value from function
596596 // Perform Autolinker's default anchor tag generation
597- var tagBuilder = this . getTagBuilder ( ) ,
598- anchorTag = tagBuilder . build ( match ) ; // returns an Autolinker.HtmlTag instance
597+ var anchorTag = match . buildTag ( ) ; // returns an Autolinker.HtmlTag instance
599598
600599 return anchorTag . toAnchorString ( ) ;
601600 }
@@ -629,13 +628,15 @@ Autolinker.prototype = {
629628 */
630629 getMatchers : function ( ) {
631630 if ( ! this . matchers ) {
632- var matchersNs = Autolinker . matcher ;
631+ var matchersNs = Autolinker . matcher ,
632+ tagBuilder = this . getTagBuilder ( ) ;
633+
633634 var matchers = [
634- new matchersNs . Hashtag ( { serviceName : this . hashtag } ) ,
635- new matchersNs . Email ( ) ,
636- new matchersNs . Phone ( ) ,
637- new matchersNs . Twitter ( ) ,
638- new matchersNs . Url ( { stripPrefix : this . stripPrefix } )
635+ new matchersNs . Hashtag ( { tagBuilder : tagBuilder , serviceName : this . hashtag } ) ,
636+ new matchersNs . Email ( { tagBuilder : tagBuilder } ) ,
637+ new matchersNs . Phone ( { tagBuilder : tagBuilder } ) ,
638+ new matchersNs . Twitter ( { tagBuilder : tagBuilder } ) ,
639+ new matchersNs . Url ( { tagBuilder : tagBuilder , stripPrefix : this . stripPrefix } )
639640 ] ;
640641
641642 return ( this . matchers = matchers ) ;
0 commit comments