@@ -14,7 +14,7 @@ So, this utility attempts to handle everything. It:
14
14
- Will properly handle URLs with query parameters or a named anchor (i.e. hash)
15
15
- Will autolink email addresses.
16
16
- Will autolink phone numbers.
17
- - Will autolink Twitter handles .
17
+ - Will autolink mentions ( Twitter, Instagram) .
18
18
- Will autolink hashtags.
19
19
- Will properly handle HTML input. The utility will not change the ` href `
20
20
attribute inside anchor (< ; a> ; ) tags (or any other tag/attribute for that
@@ -109,66 +109,71 @@ providing an Object as the second parameter to [Autolinker.link()](http://gregja
109
109
hashtags should be truncated to inside the text of a link. If the match is
110
110
over the number of characters, it will be truncated to this length by
111
111
replacing the end of the string with a two period ellipsis ('..').<br /><br />
112
-
112
+
113
113
Example: a url like 'http://www.yahoo.com/some/long/path/to/a/file ' truncated
114
114
to 25 characters may look like this: 'yahoo.com/some/long/pat..'<br /><br />
115
-
116
- In the object form, both ` length ` and ` location ` may be specified to perform
117
- truncation. Available options for ` location ` are: 'end' (default), 'middle',
118
- or 'smart'. Example usage:
119
-
115
+
116
+ In the object form, both ` length ` and ` location ` may be specified to perform
117
+ truncation. Available options for ` location ` are: 'end' (default), 'middle',
118
+ or 'smart'. Example usage:
119
+
120
120
``` javascript
121
121
truncate: { length: 32 , location: ' middle' }
122
122
```
123
-
124
- The ' smart' truncation option is for URLs where the algorithm attempts to
125
- strip out unnecessary parts of the URL (such as the ' www.' , then URL scheme,
126
- hash, etc.) before trying to find a good point to insert the ellipsis if it is
127
- still too long . For details, see source code of:
123
+
124
+ The ' smart' truncation option is for URLs where the algorithm attempts to
125
+ strip out unnecessary parts of the URL (such as the ' www.' , then URL scheme,
126
+ hash, etc.) before trying to find a good point to insert the ellipsis if it is
127
+ still too long . For details, see source code of:
128
128
[TruncateSmart](http: // gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker.truncate.TruncateSmart)
129
129
- [className](http: // gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-className) : String<br />
130
130
A CSS class name to add to the generated anchor tags . This class will be added
131
- to all links, as well as this class plus " url" / " email" / " phone" / " twitter" / " hashtag "
132
- suffixes for styling url/ email/ phone/ twitter / hashtag links differently.
131
+ to all links, as well as this class plus " url" / " email" / " phone" / " hashtag " / " mention " / " twitter" / " instagram "
132
+ suffixes for styling url/ email/ phone/ hashtag/ mention links differently.
133
133
134
134
For example, if this config is provided as " myLink" , then:
135
135
136
136
1 ) URL links will have the CSS classes: " myLink myLink-url" < br / >
137
137
2 ) Email links will have the CSS classes: " myLink myLink-email" < br / >
138
138
3 ) Phone links will have the CSS classes: " myLink myLink-phone" < br / >
139
- 4 ) Twitter links will have the CSS classes: " myLink myLink-twitter" < br / >
139
+ 4 ) Twitter links will have the CSS classes: " myLink myLink-mention myLink-twitter" < br / >
140
+ 5 ) Instagram links will have the CSS classes: " myLink myLink-mention myLink-instagram" < br / >
140
141
5 ) Hashtag links will have the CSS classes: " myLink myLink-hashtag" < br / >
141
142
142
143
- [urls](http: // gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-urls) : Boolean/Object<br />
143
144
` true` to have URLs auto- linked, ` false` to skip auto- linking of URLs.
144
145
Defaults to ` true` .< br>
145
-
146
+
146
147
This option also accepts an Object form with 3 properties, to allow for more
147
148
customization of what exactly gets linked . All default to ` true` :
148
-
149
+
149
150
- schemeMatches (Boolean ): ` true` to match URLs found prefixed with a scheme,
150
151
i .e . ` http://google.com` , or ` other+scheme://google.com` , ` false` to
151
152
prevent these types of matches.
152
153
- wwwMatches (Boolean ): ` true` to match urls found prefixed with ` 'www.'` ,
153
- i .e . ` www.google.com` . ` false` to prevent these types of matches . Note
154
- that if the URL had a prefixed scheme, and ` schemeMatches` is true , it
154
+ i .e . ` www.google.com` . ` false` to prevent these types of matches . Note
155
+ that if the URL had a prefixed scheme, and ` schemeMatches` is true , it
155
156
will still be linked.
156
157
- tldMatches: ` true` to match URLs with known top level domains (.com , .net ,
157
- etc.) that are not prefixed with a scheme or ` 'www.'` . Ex : ` google.com` ,
158
+ etc.) that are not prefixed with a scheme or ` 'www.'` . Ex : ` google.com` ,
158
159
` asdf.org/?page=1` , etc. ` false` to prevent these types of matches.
159
160
< br / >
160
-
161
+
161
162
Example usage: ` urls: { schemeMatches: true, wwwMatches: true, tldMatches: false }`
162
-
163
+
163
164
- [email](http: // gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-email) : Boolean<br />
164
165
` true` to have email addresses auto- linked, ` false` to skip auto- linking of
165
166
email addresses . Defaults to ` true` .< br / >< br / >
166
167
- [phone](http: // gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-phone) : Boolean<br />
167
168
` true` to have phone numbers auto- linked, ` false` to skip auto- linking of
168
169
phone numbers . Defaults to ` true` .< br / >< br / >
169
- - [twitter](http: // gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-twitter) : Boolean<br />
170
+ - [twitter](http: // gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-twitter) (deprecated) : Boolean<br />
170
171
` true` to have Twitter handles auto- linked, ` false` to skip auto- linking of
171
172
Twitter handles . Defaults to ` true` .< br / >< br / >
173
+ - [mention](http: // gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-mention) : String<br />
174
+ A string for the service name to have mentions (@username) auto- linked to . Supported
175
+ values at this time are ' twitter' , and ' instagram' . Pass ` false` to skip
176
+ auto- linking of mentions . Overrides ` twitter` parameter . Defaults to ` twitter` .< br / >< br / >
172
177
- [hashtag](http: // gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-hashtag) : Boolean/String<br />
173
178
A string for the service name to have hashtags auto- linked to . Supported
174
179
values at this time are ' twitter' , ' facebook' and ' instagram' . Pass ` false` to skip
@@ -231,7 +236,7 @@ individual basis, based on the return from this function.
231
236
#### Full example, for purposes of documenting the API:
232
237
233
238
```javascript
234
- var input = "..."; // string with URLs, Email Addresses, Twitter Handles , and Hashtags
239
+ var input = "..."; // string with URLs, Email Addresses, Mentions ( Twitter, Instagram) , and Hashtags
235
240
236
241
var linkedText = Autolinker.link ( input , {
237
242
replaceFn : function ( autolinker , match ) {
@@ -241,7 +246,7 @@ var linkedText = Autolinker.link( input, {
241
246
switch ( match .getType () ) {
242
247
case ' url' :
243
248
console .log ( " url: " , match .getUrl () );
244
-
249
+
245
250
return true ; // let Autolinker perform its normal anchor tag replacement
246
251
247
252
case ' email' :
@@ -259,10 +264,11 @@ var linkedText = Autolinker.link( input, {
259
264
260
265
return ' <a href="http://newplace.to.link.phone.numbers.to/">' + match .getNumber () + ' </a>' ;
261
266
262
- case ' twitter' :
263
- console .log ( " Twitter Handle: " , match .getTwitterHandle () );
267
+ case ' mention' :
268
+ console .log ( " Mention: " , match .getMention () );
269
+ console .log ( " Mention Service Name: " , match .getServiceName () );
264
270
265
- return ' <a href="http://newplace.to.link.twitter .handles.to/">' + match .getTwitterHandle () + ' </a>' ;
271
+ return ' <a href="http://newplace.to.link.mention .handles.to/">' + match .getMention () + ' </a>' ;
266
272
267
273
case ' hashtag' :
268
274
console .log ( " Hashtag: " , match .getHashtag () );
@@ -276,13 +282,13 @@ var linkedText = Autolinker.link( input, {
276
282
#### Modifying the default generated anchor tag
277
283
278
284
```javascript
279
- var input = "..."; // string with URLs, Email Addresses, Twitter Handles , and Hashtags
285
+ var input = "..."; // string with URLs, Email Addresses, Mentions ( Twitter, Instagram) , and Hashtags
280
286
281
287
var linkedText = Autolinker.link( input, {
282
288
replaceFn : function ( autolinker , match ) {
283
289
console .log ( " href = " , match .getAnchorHref () );
284
290
console .log ( " text = " , match .getAnchorText () );
285
-
291
+
286
292
var tag = match .buildTag (); // returns an `Autolinker.HtmlTag` instance for an <a> tag
287
293
tag .setAttr ( ' rel' , ' nofollow' ); // adds a 'rel' attribute
288
294
tag .addClass ( ' external-link' ); // adds a CSS class
0 commit comments