Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 34ab512

Browse files
committedAug 12, 2015
Add optional nofollow parameter to linky
1 parent d33cedd commit 34ab512

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed
 

‎src/ngSanitize/filter/linky.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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
@@ -61,6 +62,15 @@
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>&lt;div ng-bind-html="snippetWithNofollow | linky:'_self':true"&gt;<br>&lt;/div&gt;</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>&lt;div ng-bind="snippet"&gt;<br>&lt;/div&gt;</pre></td>
@@ -99,6 +109,13 @@
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
/((ftp|https?):\/\/|(www\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"\u201d\u2019]/i,
108125
MAILTO_REGEXP = /^mailto:/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, '&quot;'),
148168
'">');

0 commit comments

Comments
 (0)
This repository has been archived.