Skip to content

Add support for soundcloud mentions #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ So, this utility attempts to handle everything. It:
- Will properly handle URLs with query parameters or a named anchor (i.e. hash)
- Will autolink email addresses.
- Will autolink phone numbers.
- Will autolink mentions (Twitter, Instagram).
- Will autolink mentions (Twitter, Instagram, Soundcloud).
- Will autolink hashtags.
- Will properly handle HTML input. The utility will not change the `href`
attribute inside anchor (<a>) tags (or any other tag/attribute),
Expand All @@ -29,8 +29,7 @@ Live Example: [http://gregjacobs.github.io/Autolinker.js/examples/live-example/]

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

1. `twitter` option removed, replaced with `mention` (which accepts 'twitter'
and 'instagram' values)
1. `twitter` option removed, replaced with `mention` (which accepts 'twitter', 'instagram' and 'soundcloud' values)
2. Matching mentions (previously the `twitter` option) now defaults to
being turned off. Previously, Twitter handle matching was on by
default.
Expand Down Expand Up @@ -147,7 +146,7 @@ providing an Object as the second parameter to [Autolinker.link()](http://gregja
phone numbers. Defaults to `true`.<br /><br />
- [mention](http://gregjacobs.github.io/Autolinker.js/api/#!/api/Autolinker-cfg-mention) : String<br />
A string for the service name to have mentions (@username) auto-linked to. Supported
values at this time are 'twitter', and 'instagram'. Pass `false` to skip
values at this time are 'twitter', 'soundcloud' and 'instagram'. Pass `false` to skip
auto-linking of mentions. Defaults to `false`.<br /><br />
- [hashtag](http://gregjacobs.github.io/Autolinker.js/api/#!/api/Autolinker-cfg-hashtag) : Boolean/String<br />
A string for the service name to have hashtags auto-linked to. Supported
Expand Down
20 changes: 12 additions & 8 deletions dist/Autolinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
*
* If the configuration options do not provide enough flexibility, a {@link #replaceFn}
* may be provided to fully customize the output of Autolinker. This function is
* called once for each URL/Email/Phone#/Hashtag/Mention (Twitter, Instagram)
* called once for each URL/Email/Phone#/Hashtag/Mention (Twitter, Instagram, Soundcloud)
* match that is encountered.
*
* For example:
*
* var input = "..."; // string with URLs, Email Addresses, Phone #s, Hashtags, and Mentions (Twitter, Instagram)
* var input = "..."; // string with URLs, Email Addresses, Phone #s, Hashtags, and Mentions (Twitter, Instagram, Soundcloud)
*
* var linkedText = Autolinker.link( input, {
* replaceFn : function( match ) {
Expand Down Expand Up @@ -143,7 +143,7 @@ var Autolinker = function( cfg ) {

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

Expand Down Expand Up @@ -318,6 +318,7 @@ Autolinker.prototype = {
*
* - 'twitter'
* - 'instagram'
* - 'soundcloud'
*
* Defaults to `false` to skip auto-linking of mentions.
*/
Expand Down Expand Up @@ -444,7 +445,7 @@ Autolinker.prototype = {
* - Phone links will have the CSS classes: "myLink myLink-phone"
* - Hashtag links will have the CSS classes: "myLink myLink-hashtag"
* - Mention links will have the CSS classes: "myLink myLink-mention myLink-[type]"
* where [type] is either "instagram" or "twitter"
* where [type] is either "instagram", "twitter" or "soundcloud"
*/

/**
Expand Down Expand Up @@ -772,7 +773,7 @@ Autolinker.prototype = {

/**
* Automatically links URLs, Email addresses, Phone numbers, Hashtags,
* and Mentions (Twitter, Instagram) found in the given chunk of HTML. Does not link
* and Mentions (Twitter, Instagram, Soundcloud) found in the given chunk of HTML. Does not link
* URLs found within HTML tags.
*
* For instance, if given the text: `You should go to http://www.yahoo.com`,
Expand Down Expand Up @@ -2342,7 +2343,7 @@ Autolinker.htmlParser.TextNode = Autolinker.Util.extend( Autolinker.htmlParser.H
*
* For example:
*
* var input = "..."; // string with URLs, Email Addresses, and Mentions (Twitter, Instagram)
* var input = "..."; // string with URLs, Email Addresses, and Mentions (Twitter, Instagram, Soundcloud)
*
* var linkedText = Autolinker.link( input, {
* replaceFn : function( match ) {
Expand Down Expand Up @@ -2850,7 +2851,7 @@ Autolinker.match.Mention = Autolinker.Util.extend( Autolinker.match.Match, {

/**
* Returns the configured {@link #serviceName} to point the mention to.
* Ex: 'instagram', 'twitter'.
* Ex: 'instagram', 'twitter', 'soundcloud'.
*
* @return {String}
*/
Expand All @@ -2870,6 +2871,8 @@ Autolinker.match.Mention = Autolinker.Util.extend( Autolinker.match.Match, {
return 'https://twitter.com/' + this.mention;
case 'instagram' :
return 'https://instagram.com/' + this.mention;
case 'soundcloud' :
return 'https://soundcloud.com/' + this.mention;

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

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/Autolinker.min.js

Large diffs are not rendered by default.

Loading