1515 *
1616 * @param {string } text Input text.
1717 * @param {string } target Window (_blank|_self|_parent|_top) or named frame to open links in.
18+ * @param {boolean } nofollow Add rel=nofollow to links.
1819 * @returns {string } Html-linkified text.
1920 *
2021 * @usage
6162 <div ng-bind-html="snippetWithTarget | linky:'_blank'"></div>
6263 </td>
6364 </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>
6474 <tr id="escaped-html">
6575 <td>no filter</td>
6676 <td><pre><div ng-bind="snippet"><br></div></pre></td>
99109 toBe('http://angularjs.org/');
100110 expect(element(by.css('#linky-target a')).getAttribute('target')).toEqual('_blank');
101111 });
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+ });
102119 </file>
103120 </example>
104121 */
@@ -107,7 +124,7 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
107124 / ( ( 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,
108125 MAILTO_REGEXP = / ^ m a i l t o : / i;
109126
110- return function ( text , target ) {
127+ return function ( text , target , nofollow ) {
111128 if ( ! text ) return text ;
112129 var match ;
113130 var raw = text ;
@@ -143,6 +160,9 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
143160 target ,
144161 '" ' ) ;
145162 }
163+ if ( nofollow ) {
164+ html . push ( 'rel="nofollow" ' ) ;
165+ }
146166 html . push ( 'href="' ,
147167 url . replace ( / " / g, '"' ) ,
148168 '">' ) ;
0 commit comments