Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 3241947

Browse files
committed
Add optional nofollow parameter to linky
1 parent d33cedd commit 3241947

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/ngSanitize/filter/linky.js

+12-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
@@ -99,6 +100,13 @@
99100
toBe('http://angularjs.org/');
100101
expect(element(by.css('#linky-target a')).getAttribute('target')).toEqual('_blank');
101102
});
103+
104+
it('should optionally add nofollow', function() {
105+
expect(element(by.id('linky-target')).
106+
element(by.binding("snippetWithTarget | linky:'_self':true")).getText()).
107+
toBe('http://angularjs.org/');
108+
expect(element(by.css('#linky-target a')).getAttribute('rel')).toEqual('nofollow');
109+
});
102110
</file>
103111
</example>
104112
*/
@@ -107,7 +115,7 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
107115
/((ftp|https?):\/\/|(www\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"\u201d\u2019]/i,
108116
MAILTO_REGEXP = /^mailto:/i;
109117

110-
return function(text, target) {
118+
return function(text, target, nofollow) {
111119
if (!text) return text;
112120
var match;
113121
var raw = text;
@@ -143,6 +151,9 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
143151
target,
144152
'" ');
145153
}
154+
if (nofollow) {
155+
html.push('rel="nofollow" ');
156+
}
146157
html.push('href="',
147158
url.replace(/"/g, '&quot;'),
148159
'">');

0 commit comments

Comments
 (0)