forked from bryanwoods/autolink-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autolink.js
34 lines (31 loc) · 1.18 KB
/
autolink.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//@ sourceMappingURL=autolink.map
// Generated by CoffeeScript 1.6.1
(function() {
var autoLink,
__slice = [].slice;
autoLink = function() {
var callbackThunk, key, link_attributes, option, options, url_pattern, value;
options = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
link_attributes = '';
option = options[0];
url_pattern = /(^|\s)(\b(https?|ftp):\/\/[\-A-Z0-9+\u0026@#\/%?=~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~_|])/gi;
if (!(options.length > 0)) {
return this.replace(url_pattern, "$1<a href='$2'>$2</a>");
}
if ((option['callback'] != null) && typeof option['callback'] === 'function') {
callbackThunk = option['callback'];
delete option['callback'];
}
for (key in option) {
value = option[key];
link_attributes += " " + key + "='" + value + "'";
}
return this.replace(url_pattern, function(match, space, url) {
var link, returnCallback;
returnCallback = callbackThunk && callbackThunk(url);
link = returnCallback || ("<a href='" + url + "'" + link_attributes + ">" + url + "</a>");
return "" + space + link;
});
};
String.prototype['autoLink'] = autoLink;
}).call(this);