15
15
*
16
16
* @param {string } text Input text.
17
17
* @param {string } target Window (_blank|_self|_parent|_top) or named frame to open links in.
18
+ * @param {boolean } nofollow Add rel=nofollow to links.
18
19
* @returns {string } Html-linkified text.
19
20
*
20
21
* @usage
61
62
<div ng-bind-html="snippetWithTarget | linky:'_blank'"></div>
62
63
</td>
63
64
</tr>
65
+ <tr id="linky-nofollow">
66
+ <td>linky nofollow</td>
67
+ <td>
68
+ <pre><div ng-bind-html="snippetWithNofollow | linky:'_self':true"><br></div></pre>
69
+ </td>
70
+ <td>
71
+ <div ng-bind-html="snippetWithNofollow | linky:'_self':true"></div>
72
+ </td>
73
+ </tr>
64
74
<tr id="escaped-html">
65
75
<td>no filter</td>
66
76
<td><pre><div ng-bind="snippet"><br></div></pre></td>
99
109
toBe('http://angularjs.org/');
100
110
expect(element(by.css('#linky-target a')).getAttribute('target')).toEqual('_blank');
101
111
});
112
+
113
+ it('should optionally add nofollow', function() {
114
+ expect(element(by.id('linky-nofollow')).
115
+ element(by.binding("snippetWithNofollow | linky:'_self':true")).getText()).
116
+ toBe('http://angularjs.org/');
117
+ expect(element(by.css('#linky-nofollow a')).getAttribute('rel')).toEqual('nofollow');
118
+ });
102
119
</file>
103
120
</example>
104
121
*/
@@ -107,7 +124,7 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
107
124
/ ( ( f t p | h t t p s ? ) : \/ \/ | ( w w w \. ) | ( m a i l t o : ) ? [ A - Z a - z 0 - 9 . _ % + - ] + @ ) \S * [ ^ \s . ; , ( ) { } < > " \u201d \u2019 ] / i,
108
125
MAILTO_REGEXP = / ^ m a i l t o : / i;
109
126
110
- return function ( text , target ) {
127
+ return function ( text , target , nofollow ) {
111
128
if ( ! text ) return text ;
112
129
var match ;
113
130
var raw = text ;
@@ -143,6 +160,9 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
143
160
target ,
144
161
'" ' ) ;
145
162
}
163
+ if ( nofollow ) {
164
+ html . push ( 'rel="nofollow" ' ) ;
165
+ }
146
166
html . push ( 'href="' ,
147
167
url . replace ( / " / g, '"' ) ,
148
168
'">' ) ;
0 commit comments