Skip to content

Commit 0234067

Browse files
authored
Merge pull request #243 from Superjo149/master
Add support for soundcloud mentions
2 parents 03bb04c + 0b47d8f commit 0234067

File tree

9 files changed

+8079
-22
lines changed

9 files changed

+8079
-22
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ So, this utility attempts to handle everything. It:
1414
- Will properly handle URLs with query parameters or a named anchor (i.e. hash)
1515
- Will autolink email addresses.
1616
- Will autolink phone numbers.
17-
- Will autolink mentions (Twitter, Instagram).
17+
- Will autolink mentions (Twitter, Instagram, Soundcloud).
1818
- Will autolink hashtags.
1919
- Will properly handle HTML input. The utility will not change the `href`
2020
attribute inside anchor (<a>) tags (or any other tag/attribute),
@@ -29,8 +29,7 @@ Live Example: [http://gregjacobs.github.io/Autolinker.js/examples/live-example/]
2929

3030
## v1.0 released. Breaking Changes from 0.x -> 1.x
3131

32-
1. `twitter` option removed, replaced with `mention` (which accepts 'twitter'
33-
and 'instagram' values)
32+
1. `twitter` option removed, replaced with `mention` (which accepts 'twitter', 'instagram' and 'soundcloud' values)
3433
2. Matching mentions (previously the `twitter` option) now defaults to
3534
being turned off. Previously, Twitter handle matching was on by
3635
default.
@@ -147,7 +146,7 @@ providing an Object as the second parameter to [Autolinker.link()](http://gregja
147146
phone numbers. Defaults to `true`.<br /><br />
148147
- [mention](http://gregjacobs.github.io/Autolinker.js/api/#!/api/Autolinker-cfg-mention) : String<br />
149148
A string for the service name to have mentions (@username) auto-linked to. Supported
150-
values at this time are 'twitter', and 'instagram'. Pass `false` to skip
149+
values at this time are 'twitter', 'soundcloud' and 'instagram'. Pass `false` to skip
151150
auto-linking of mentions. Defaults to `false`.<br /><br />
152151
- [hashtag](http://gregjacobs.github.io/Autolinker.js/api/#!/api/Autolinker-cfg-hashtag) : Boolean/String<br />
153152
A string for the service name to have hashtags auto-linked to. Supported

dist/Autolinker.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
*
5454
* If the configuration options do not provide enough flexibility, a {@link #replaceFn}
5555
* may be provided to fully customize the output of Autolinker. This function is
56-
* called once for each URL/Email/Phone#/Hashtag/Mention (Twitter, Instagram)
56+
* called once for each URL/Email/Phone#/Hashtag/Mention (Twitter, Instagram, Soundcloud)
5757
* match that is encountered.
5858
*
5959
* For example:
6060
*
61-
* var input = "..."; // string with URLs, Email Addresses, Phone #s, Hashtags, and Mentions (Twitter, Instagram)
61+
* var input = "..."; // string with URLs, Email Addresses, Phone #s, Hashtags, and Mentions (Twitter, Instagram, Soundcloud)
6262
*
6363
* var linkedText = Autolinker.link( input, {
6464
* replaceFn : function( match ) {
@@ -143,7 +143,7 @@ var Autolinker = function( cfg ) {
143143

144144
// Validate the value of the `mention` cfg
145145
var mention = this.mention;
146-
if( mention !== false && mention !== 'twitter' && mention !== 'instagram' ) {
146+
if( mention !== false && mention !== 'twitter' && mention !== 'instagram' && mention !== 'soundcloud' ) {
147147
throw new Error( "invalid `mention` cfg - see docs" );
148148
}
149149

@@ -318,6 +318,7 @@ Autolinker.prototype = {
318318
*
319319
* - 'twitter'
320320
* - 'instagram'
321+
* - 'soundcloud'
321322
*
322323
* Defaults to `false` to skip auto-linking of mentions.
323324
*/
@@ -444,7 +445,7 @@ Autolinker.prototype = {
444445
* - Phone links will have the CSS classes: "myLink myLink-phone"
445446
* - Hashtag links will have the CSS classes: "myLink myLink-hashtag"
446447
* - Mention links will have the CSS classes: "myLink myLink-mention myLink-[type]"
447-
* where [type] is either "instagram" or "twitter"
448+
* where [type] is either "instagram", "twitter" or "soundcloud"
448449
*/
449450

450451
/**
@@ -772,7 +773,7 @@ Autolinker.prototype = {
772773

773774
/**
774775
* Automatically links URLs, Email addresses, Phone numbers, Hashtags,
775-
* and Mentions (Twitter, Instagram) found in the given chunk of HTML. Does not link
776+
* and Mentions (Twitter, Instagram, Soundcloud) found in the given chunk of HTML. Does not link
776777
* URLs found within HTML tags.
777778
*
778779
* For instance, if given the text: `You should go to http://www.yahoo.com`,
@@ -2342,7 +2343,7 @@ Autolinker.htmlParser.TextNode = Autolinker.Util.extend( Autolinker.htmlParser.H
23422343
*
23432344
* For example:
23442345
*
2345-
* var input = "..."; // string with URLs, Email Addresses, and Mentions (Twitter, Instagram)
2346+
* var input = "..."; // string with URLs, Email Addresses, and Mentions (Twitter, Instagram, Soundcloud)
23462347
*
23472348
* var linkedText = Autolinker.link( input, {
23482349
* replaceFn : function( match ) {
@@ -2850,7 +2851,7 @@ Autolinker.match.Mention = Autolinker.Util.extend( Autolinker.match.Match, {
28502851

28512852
/**
28522853
* Returns the configured {@link #serviceName} to point the mention to.
2853-
* Ex: 'instagram', 'twitter'.
2854+
* Ex: 'instagram', 'twitter', 'soundcloud'.
28542855
*
28552856
* @return {String}
28562857
*/
@@ -2870,6 +2871,8 @@ Autolinker.match.Mention = Autolinker.Util.extend( Autolinker.match.Match, {
28702871
return 'https://twitter.com/' + this.mention;
28712872
case 'instagram' :
28722873
return 'https://instagram.com/' + this.mention;
2874+
case 'soundcloud' :
2875+
return 'https://soundcloud.com/' + this.mention;
28732876

28742877
default : // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case.
28752878
throw new Error( 'Unknown service name to point mention to: ', this.serviceName );
@@ -3479,7 +3482,8 @@ Autolinker.matcher.Mention = Autolinker.Util.extend( Autolinker.matcher.Matcher,
34793482
*/
34803483
matcherRegexes : {
34813484
"twitter": new RegExp( '@[_' + Autolinker.RegexLib.alphaNumericCharsStr + ']{1,20}', 'g' ),
3482-
"instagram": new RegExp( '@[_.' + Autolinker.RegexLib.alphaNumericCharsStr + ']{1,50}', 'g' )
3485+
"instagram": new RegExp( '@[_.' + Autolinker.RegexLib.alphaNumericCharsStr + ']{1,50}', 'g' ),
3486+
"soundcloud": new RegExp( '@[_.' + Autolinker.RegexLib.alphaNumericCharsStr + "\-" + ']{1,50}', 'g' )
34833487
},
34843488

34853489
/**

dist/Autolinker.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)