Skip to content

Commit

Permalink
Allow linking of instagram hashtags
Browse files Browse the repository at this point in the history
  • Loading branch information
Friss committed Aug 22, 2015
1 parent 3961ba6 commit bb0cef6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Autolinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var Autolinker = function( cfg ) {

// Validate the value of the `hashtag` cfg.
var hashtag = this.hashtag;
if( hashtag !== false && hashtag !== 'twitter' && hashtag !== 'facebook' ) {
if( hashtag !== false && hashtag !== 'twitter' && hashtag !== 'facebook' && hashtag !== 'instagram' ) {
throw new Error( "invalid `hashtag` cfg - see docs" );
}
};
Expand Down Expand Up @@ -153,6 +153,7 @@ Autolinker.prototype = {
*
* - 'twitter'
* - 'facebook'
* - 'instagram'
*
* Pass `false` to skip auto-linking of hashtags.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/match/Hashtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Autolinker.match.Hashtag = Autolinker.Util.extend( Autolinker.match.Match, {
return 'https://twitter.com/hashtag/' + hashtag;
case 'facebook' :
return 'https://www.facebook.com/hashtag/' + hashtag;
case 'instagram' :
return 'https://instagram.com/explore/tags/' + hashtag;

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 hashtag to: ', serviceName );
Expand All @@ -75,4 +77,4 @@ Autolinker.match.Hashtag = Autolinker.Util.extend( Autolinker.match.Match, {
return '#' + this.hashtag;
}

} );
} );
7 changes: 7 additions & 0 deletions tests/AutolinkerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ describe( "Autolinker", function() {
beforeEach( function() {
twitterHashtagAutolinker = new Autolinker( { hashtag: 'twitter', newWindow: false } );
facebookHashtagAutolinker = new Autolinker( { hashtag: 'facebook', newWindow: false } );
instagramHashtagAutolinker = new Autolinker( { hashtag: 'instagram', newWindow: false } );
} );


Expand Down Expand Up @@ -942,6 +943,12 @@ describe( "Autolinker", function() {
expect( result ).toBe( '<a href="https://www.facebook.com/hashtag/test">#test</a>' );
} );

it( "should automatically link hashtags to instagram when the `hashtag` option is 'instagram'", function() {
var result = instagramHashtagAutolinker.link( "#test" );

expect( result ).toBe( '<a href="https://instagram.com/explore/tags/test">#test</a>' );
} );


it( "should automatically link hashtags which are part of a full string", function() {
var result = twitterHashtagAutolinker.link( "my hashtag is #test these days" );
Expand Down

0 comments on commit bb0cef6

Please sign in to comment.