Skip to content

Commit 67a0908

Browse files
committed
Have Autolinker link fully-capitalized URLs/Emails/Twitter handles.
1 parent 972e878 commit 67a0908

File tree

6 files changed

+49
-9
lines changed

6 files changed

+49
-9
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ autolinker.link( "Go to www.google.com" );
148148

149149
## Changelog:
150150

151+
### 0.11.0
152+
153+
- Allow Autolinker to link fully-capitalized URLs/Emails/Twitter handles.
154+
151155
### 0.10.1
152156

153157
- Added fix to not autolink strings like "version:1.0", which were accidentally being interpreted as a protocol:domain string.

dist/Autolinker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* Autolinker.js
3-
* 0.10.1
3+
* 0.11.0
44
*
55
* Copyright(c) 2014 Gregory Jacobs <[email protected]>
66
* MIT Licensed. http://www.opensource.org/licenses/mit-license.php
@@ -207,7 +207,7 @@
207207

208208
urlSuffixRegex.source, // match for path, query string, and/or hash anchor
209209
')'
210-
].join( "" ), 'g' );
210+
].join( "" ), 'gi' );
211211
} )(),
212212

213213
/**
@@ -263,7 +263,7 @@
263263
*
264264
* A regular expression used to remove the 'http://' or 'https://' and/or the 'www.' from URLs.
265265
*/
266-
urlPrefixRegex: /^(https?:\/\/)?(www\.)?/,
266+
urlPrefixRegex: /^(https?:\/\/)?(www\.)?/i,
267267

268268

269269
/**

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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "autolinker",
3-
"version": "0.10.1",
3+
"version": "0.11.0",
44
"description": "Simple utility to automatically link the URLs, email addresses, and Twitter handles in a given block of text/HTML",
55
"main": "dist/Autolinker.js",
66
"directories": {

src/Autolinker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198

199199
urlSuffixRegex.source, // match for path, query string, and/or hash anchor
200200
')'
201-
].join( "" ), 'g' );
201+
].join( "" ), 'gi' );
202202
} )(),
203203

204204
/**
@@ -254,7 +254,7 @@
254254
*
255255
* A regular expression used to remove the 'http://' or 'https://' and/or the 'www.' from URLs.
256256
*/
257-
urlPrefixRegex: /^(https?:\/\/)?(www\.)?/,
257+
urlPrefixRegex: /^(https?:\/\/)?(www\.)?/i,
258258

259259

260260
/**

tests/AutolinkerSpec.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ describe( "Autolinker", function() {
3737
} );
3838

3939

40-
it( "should automatically link URLs in the form of https://yahoo.com (https)", function() {
40+
it( "should automatically link https URLs in the form of https://yahoo.com", function() {
4141
var result = autolinker.link( "Joe went to https://www.yahoo.com" );
4242
expect( result ).toBe( 'Joe went to <a href="https://www.yahoo.com">yahoo.com</a>' );
4343
} );
4444

4545

46+
it( "should automatically link capitalized URLs", function() {
47+
var result = autolinker.link( "Joe went to HTTP://WWW.YAHOO.COM" );
48+
expect( result ).toBe( 'Joe went to <a href="HTTP://WWW.YAHOO.COM">YAHOO.COM</a>' );
49+
} );
50+
51+
4652
it( "should automatically link 'yahoo.xyz' (a known TLD), but not 'sencha.etc' (an unknown TLD)", function() {
4753
var result = autolinker.link( "yahoo.xyz should be linked, sencha.etc should not", { newWindow: false } );
4854
expect( result ).toBe( '<a href="http://yahoo.xyz">yahoo.xyz</a> should be linked, sencha.etc should not' );
@@ -157,6 +163,12 @@ describe( "Autolinker", function() {
157163
expect( result ).toBe( 'Joe went to <a href="http://www.yahoo.com:8000">yahoo.com:8000</a> today' );
158164
} );
159165

166+
167+
it( "should automatically link capitalized URLs", function() {
168+
var result = autolinker.link( "Joe went to WWW.YAHOO.COM today" );
169+
expect( result ).toBe( 'Joe went to <a href="http://WWW.YAHOO.COM">YAHOO.COM</a> today' );
170+
} );
171+
160172
} );
161173

162174

@@ -197,6 +209,12 @@ describe( "Autolinker", function() {
197209
expect( result ).toBe( 'Joe went to <a href="http://yahoo.com:8000">yahoo.com:8000</a> today' );
198210
} );
199211

212+
213+
it( "should automatically link capitalized URLs", function() {
214+
var result = autolinker.link( "Joe went to YAHOO.COM." );
215+
expect( result ).toBe( 'Joe went to <a href="http://YAHOO.COM">YAHOO.COM</a>.' );
216+
} );
217+
200218
} );
201219

202220

@@ -220,6 +238,12 @@ describe( "Autolinker", function() {
220238
} );
221239

222240

241+
it( "should automatically link capitalized protocol-relative URLs", function() {
242+
var result = autolinker.link( "Joe went to //YAHOO.COM" );
243+
expect( result ).toBe( 'Joe went to <a href="//YAHOO.COM">YAHOO.COM</a>' );
244+
} );
245+
246+
223247
it( "should NOT automatically link supposed protocol-relative URLs in the form of abc//yahoo.com, which is most likely not supposed to be interpreted as a URL", function() {
224248
var result = autolinker.link( "Joe went to abc//yahoo.com" );
225249
expect( result ).toBe( 'Joe went to abc//yahoo.com' );
@@ -414,6 +438,12 @@ describe( "Autolinker", function() {
414438
} );
415439

416440

441+
it( "should automatically link fully-capitalized email addresses", function() {
442+
var result = autolinker.link( "Joe's email is [email protected]" );
443+
expect( result ).toBe( 'Joe\'s email is <a href="mailto:[email protected]">[email protected]</a>' );
444+
} );
445+
446+
417447
it( "should NOT automatically link any old word with an @ character in it", function() {
418448
var result = autolinker.link( "Hi there@stuff" );
419449
expect( result ).toBe( 'Hi there@stuff' );
@@ -471,6 +501,12 @@ describe( "Autolinker", function() {
471501
expect( result ).toBe( '<a href="https://twitter.com/greg">@greg</a> is tweeting <a href="https://twitter.com/joe">@joe</a> with <a href="https://twitter.com/josh">@josh</a>' );
472502
} );
473503

504+
505+
it( "should automatically liny fully capitalized twitter handles", function() {
506+
var result = autolinker.link( "@GREG is tweeting @JOE with @JOSH" );
507+
expect( result ).toBe( '<a href="https://twitter.com/GREG">@GREG</a> is tweeting <a href="https://twitter.com/JOE">@JOE</a> with <a href="https://twitter.com/JOSH">@JOSH</a>' );
508+
} );
509+
474510
} );
475511

476512

0 commit comments

Comments
 (0)