You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/spec/linkify-html-test.js
+66-1Lines changed: 66 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -3,17 +3,82 @@ var htmlOptions = require('./html/options');
3
3
4
4
describe('linkify-html',function(){
5
5
6
+
varoptions={// test options
7
+
tagName: 'span',
8
+
target: '_parent',
9
+
nl2br: true,
10
+
linkClass: 'my-linkify-class',
11
+
defaultProtocol: 'https',
12
+
linkAttributes: {
13
+
rel: 'nofollow',
14
+
onclick: 'javascript:;'
15
+
},
16
+
format: function(val){
17
+
returnval.truncate(40);
18
+
},
19
+
formatHref: function(href,type){
20
+
if(type==='email'){
21
+
href+='?subject=Hello%20from%20Linkify';
22
+
}
23
+
returnhref;
24
+
}
25
+
},
26
+
27
+
// For each element in this array
28
+
// [0] - Original text
29
+
// [1] - Linkified with default options
30
+
// [2] - Linkified with new options
31
+
tests=[
32
+
[
33
+
'Test with no links',
34
+
'Test with no links',
35
+
'Test with no links'
36
+
],[
37
+
'The URL is google.com and the email is <strong>[email protected]</strong>',
38
+
'The URL is <a href="http://google.com" class="linkified" target="_blank">google.com</a> and the email is <strong><a href="mailto:[email protected]" class="linkified">[email protected]</a></strong>',
39
+
'The URL is <span href="https://google.com" class="my-linkify-class" target="_parent" rel="nofollow" onclick="javascript:;">google.com</span> and the email is <strong><span href="mailto:[email protected]?subject=Hello%20from%20Linkify" class="my-linkify-class" target="_parent" rel="nofollow" onclick="javascript:;">[email protected]</span></strong>'
40
+
],[
41
+
'Super long maps URL https://www.google.ca/maps/@43.472082,-80.5426668,18z?hl=en, a #hash-tag, and an email: test."wut"[email protected]!',
42
+
'Super long maps URL <a href="https://www.google.ca/maps/@43.472082,-80.5426668,18z?hl=en" class="linkified" target="_blank">https://www.google.ca/maps/@43.472082,-80.5426668,18z?hl=en</a>, a #hash-tag, and an email: <a href="mailto:test."wut"[email protected]" class="linkified">test."wut"[email protected]</a>!',
43
+
'Super long maps URL <span href="https://www.google.ca/maps/@43.472082,-80.5426668,18z?hl=en" class="my-linkify-class" target="_parent" rel="nofollow" onclick="javascript:;">https://www.google.ca/maps/@43.472082,-8…</span>, a #hash-tag, and an email: <span href="mailto:test."wut"[email protected]?subject=Hello%20from%20Linkify" class="my-linkify-class" target="_parent" rel="nofollow" onclick="javascript:;">test."wut"[email protected]</span>!',
44
+
],[
45
+
'This link is already in an anchor tag <a href="#bro">google.com</a> LOL and this one <h1>isnt http://github.com</h1>',
46
+
'This link is already in an anchor tag <a href="#bro">google.com</a> LOL and this one <h1>isnt <a href="http://github.com" class="linkified" target="_blank">http://github.com</a></h1>',
47
+
'This link is already in an anchor tag <a href="#bro">google.com</a> LOL and this one <h1>isnt <span href="http://github.com" class="my-linkify-class" target="_parent" rel="nofollow" onclick="javascript:;">http://github.com</span></h1>'
48
+
],[
49
+
'Unterminated anchor tag <a href="http://google.com"> This <em>is a link google.com</em> and this works!! https://reddit.com/r/photography/',
50
+
'Unterminated anchor tag <a href="http://google.com"> This <em>is a link google.com</em> and this works!! https://reddit.com/r/photography/',
51
+
'Unterminated anchor tag <a href="http://google.com"> This <em>is a link google.com</em> and this works!! https://reddit.com/r/photography/'
0 commit comments