Skip to content

Commit 3c09a24

Browse files
committed
Merge pull request #118 from Friss/add-instagram
Add instagram
2 parents 3961ba6 + b3a2339 commit 3c09a24

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ providing an Object as the second parameter to [Autolinker.link()](http://gregja
135135
Twitter handles. Defaults to `true`.<br /><br />
136136
- [hashtag](http://gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-hashtag) : Boolean/String<br />
137137
A string for the service name to have hashtags auto-linked to. Supported
138-
values at this time are 'twitter' and 'facebook'. Pass `false` to skip
138+
values at this time are 'twitter', 'facebook' and 'instagram'. Pass `false` to skip
139139
auto-linking of hashtags. Defaults to `false`.<br /><br />
140140
- [replaceFn](http://gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-replaceFn) : Function<br />
141141
A function to use to programmatically make replacements of matches in the
@@ -282,7 +282,7 @@ The full API docs for Autolinker may be referenced at:
282282

283283
Pull requests definitely welcome.
284284

285-
- Make sure to add tests to cover your new functionality/bugfix.
285+
- Make sure to add tests to cover your new functionality/bugfix.
286286
- Run the `grunt` command to build/test (or alternatively, open the `tests/index.html` file to run the tests).
287287
- When committing, please omit checking in the files in the `dist/` folder after building/testing. These are only committed to the repository for users downloading Autolinker via Bower. I will build these files and assign them a version number when merging your PR.
288288
- Please use tabs for indents! Tabs are better for everybody (individuals can set their editors to different tab sizes based on their visual preferences).

src/Autolinker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var Autolinker = function( cfg ) {
109109

110110
// Validate the value of the `hashtag` cfg.
111111
var hashtag = this.hashtag;
112-
if( hashtag !== false && hashtag !== 'twitter' && hashtag !== 'facebook' ) {
112+
if( hashtag !== false && hashtag !== 'twitter' && hashtag !== 'facebook' && hashtag !== 'instagram' ) {
113113
throw new Error( "invalid `hashtag` cfg - see docs" );
114114
}
115115
};
@@ -153,6 +153,7 @@ Autolinker.prototype = {
153153
*
154154
* - 'twitter'
155155
* - 'facebook'
156+
* - 'instagram'
156157
*
157158
* Pass `false` to skip auto-linking of hashtags.
158159
*/

src/match/Hashtag.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Autolinker.match.Hashtag = Autolinker.Util.extend( Autolinker.match.Match, {
5959
return 'https://twitter.com/hashtag/' + hashtag;
6060
case 'facebook' :
6161
return 'https://www.facebook.com/hashtag/' + hashtag;
62+
case 'instagram' :
63+
return 'https://instagram.com/explore/tags/' + hashtag;
6264

6365
default : // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case.
6466
throw new Error( 'Unknown service name to point hashtag to: ', serviceName );
@@ -75,4 +77,4 @@ Autolinker.match.Hashtag = Autolinker.Util.extend( Autolinker.match.Match, {
7577
return '#' + this.hashtag;
7678
}
7779

78-
} );
80+
} );

tests/AutolinkerSpec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ describe( "Autolinker", function() {
914914
beforeEach( function() {
915915
twitterHashtagAutolinker = new Autolinker( { hashtag: 'twitter', newWindow: false } );
916916
facebookHashtagAutolinker = new Autolinker( { hashtag: 'facebook', newWindow: false } );
917+
instagramHashtagAutolinker = new Autolinker( { hashtag: 'instagram', newWindow: false } );
917918
} );
918919

919920

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

946+
it( "should automatically link hashtags to instagram when the `hashtag` option is 'instagram'", function() {
947+
var result = instagramHashtagAutolinker.link( "#test" );
948+
949+
expect( result ).toBe( '<a href="https://instagram.com/explore/tags/test">#test</a>' );
950+
} );
951+
945952

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

0 commit comments

Comments
 (0)