1
- function linkify ( string , buildHashtagUrl , includeW3 , target ) {
1
+ function linkify ( string , buildHashtagUrl , includeW3 , target , noFollow ) {
2
+ relNoFollow = "" ;
3
+ if ( noFollow ) {
4
+ relNoFollow = " rel=\"nofollow\"" ;
5
+ }
6
+
2
7
string = string . replace ( / ( ( h t t p | h t t p s | f t p ) \: \/ \/ | \b w { 3 } \. ) [ a - z 0 - 9 \- \. ] + \. [ a - z ] { 2 , 3 } ( : [ a - z 0 - 9 ] * ) ? \/ ? ( [ a - z \u00C0 - \u017F 0 - 9 \- \. _ \? \, \' \/ \\ \+ & a m p ; % \$ # \= ~ ] ) * / gi, function ( captured ) {
3
8
var uri ;
4
9
if ( captured . toLowerCase ( ) . indexOf ( "www." ) == 0 ) {
@@ -9,11 +14,11 @@ function linkify(string, buildHashtagUrl, includeW3, target) {
9
14
} else {
10
15
uri = captured ;
11
16
}
12
- return "<a href=\"" + uri + "\" target=\"" + target + "\" rel=\"nofollow\" >" + captured + "</a>" ; ;
17
+ return "<a href=\"" + uri + "\" target=\"" + target + "\"" + relNoFollow + " >" + captured + "</a>" ;
13
18
} ) ;
14
19
15
20
if ( buildHashtagUrl ) {
16
- string = string . replace ( / \B # ( \w + ) / g, "<a href=" + buildHashtagUrl ( "$1" ) + " target=\"" + target + "\" rel=\"nofollow\ ">#$1</a>" ) ;
21
+ string = string . replace ( / \B # ( \w + ) / g, "<a href=" + buildHashtagUrl ( "$1" ) + " target=\"" + target + "\"" + relNoFollow + ">#$1</a>" ) ;
17
22
}
18
23
return string ;
19
24
}
@@ -25,6 +30,7 @@ function linkify(string, buildHashtagUrl, includeW3, target) {
25
30
var buildHashtagUrl ;
26
31
var includeW3 = true ;
27
32
var target = '_self' ;
33
+ var noFollow = true ;
28
34
if ( opts ) {
29
35
if ( typeof opts == "function" ) {
30
36
buildHashtagUrl = opts ;
@@ -38,14 +44,17 @@ function linkify(string, buildHashtagUrl, includeW3, target) {
38
44
if ( typeof opts . target == "string" ) {
39
45
target = opts . target ;
40
46
}
47
+ if ( typeof opts . noFollow == "boolean" ) {
48
+ noFollow = opts . noFollow ;
49
+ }
41
50
}
42
51
}
43
52
$this . html (
44
53
$ . map (
45
54
$this . contents ( ) ,
46
55
function ( n , i ) {
47
56
if ( n . nodeType == 3 ) {
48
- return linkify ( n . data , buildHashtagUrl , includeW3 , target ) ;
57
+ return linkify ( n . data , buildHashtagUrl , includeW3 , target , noFollow ) ;
49
58
} else {
50
59
return n . outerHTML ;
51
60
}
0 commit comments