| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
Autolinker.matcher.Mention = Autolinker.Util.extend( Autolinker.matcher.Matcher, { |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
matcherRegexes : { |
| 19 |
"twitter": new RegExp( '@[_' + Autolinker.RegexLib.alphaNumericCharsStr + ']{1,20}', 'g' ), |
| 20 |
"instagram": new RegExp( '@[_.' + Autolinker.RegexLib.alphaNumericCharsStr + ']{1,50}', 'g' ), |
| 21 |
"soundcloud": new RegExp( '@[_.' + Autolinker.RegexLib.alphaNumericCharsStr + "\-" + ']{1,50}', 'g' ) |
| 22 |
}, |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
nonWordCharRegex : new RegExp( '[^' + Autolinker.RegexLib.alphaNumericCharsStr + ']' ), |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
constructor : function( cfg ) { |
| 42 |
Autolinker.matcher.Matcher.prototype.constructor.call( this, cfg ); |
| 43 |
|
| 44 |
this.serviceName = cfg.serviceName; |
| 45 |
}, |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
parseMatches : function( text ) { |
| 52 |
var matcherRegex = this.matcherRegexes[this.serviceName], |
| 53 |
nonWordCharRegex = this.nonWordCharRegex, |
| 54 |
serviceName = this.serviceName, |
| 55 |
tagBuilder = this.tagBuilder, |
| 56 |
matches = [], |
| 57 |
match; |
| 58 |
|
| 59 |
if (!matcherRegex) { |
| 60 |
return matches; |
| 61 |
} |
| 62 |
|
| 63 |
while( ( match = matcherRegex.exec( text ) ) !== null ) { |
| 64 |
var offset = match.index, |
| 65 |
prevChar = text.charAt( offset - 1 ); |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
if( offset === 0 || nonWordCharRegex.test( prevChar ) ) { |
| 71 |
var matchedText = match[ 0 ].replace(/\.+$/g, ''), |
| 72 |
mention = matchedText.slice( 1 ); |
| 73 |
|
| 74 |
matches.push( new Autolinker.match.Mention( { |
| 75 |
tagBuilder : tagBuilder, |
| 76 |
matchedText : matchedText, |
| 77 |
offset : offset, |
| 78 |
serviceName : serviceName, |
| 79 |
mention : mention |
| 80 |
} ) ); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
return matches; |
| 85 |
} |
| 86 |
|
| 87 |
} ); |