Skip to content

Commit d4a7040

Browse files
authored
Merge pull request #1043 from andrew-boyarshin/autolink
Fix span wrapping all the things
2 parents 9ad3a07 + 817710d commit d4a7040

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

public/js/libs/autolink.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
jQuery.fn.autolink = function() {
2-
return this.find('*').contents().filter(function () { return this.nodeType === 3; }).each(function() {
3-
var re = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+:=&;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g;
4-
$(this).each(function() {
5-
$(this).replaceWith(
6-
$("<span />").html(
7-
this.nodeValue.replace(re, "<a href='$1'>$1</a>")
8-
)
9-
);
2+
var re = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+:=&;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g;
3+
return this.find('*').contents()
4+
.filter(function () { return this.nodeType === 3; })
5+
.each(function() {
6+
$(this).each(function() {
7+
if (re.test($(this).text()))
8+
$(this).replaceWith(
9+
$("<span />").html(
10+
this.nodeValue.replace(re, "<a href='$1'>$1</a>")
11+
)
12+
);
13+
});
1014
});
11-
});
1215
};

0 commit comments

Comments
 (0)