From 817710dd477e312a30c7be7f240cef9425e781dd Mon Sep 17 00:00:00 2001 From: Andrew Boyarshin Date: Fri, 24 Feb 2017 18:49:04 +0700 Subject: [PATCH] Fix span wrapping all the things Signed-off-by: Andrew Boyarshin --- public/js/libs/autolink.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/public/js/libs/autolink.js b/public/js/libs/autolink.js index a5d1e3a6e..3a9c0d4bc 100644 --- a/public/js/libs/autolink.js +++ b/public/js/libs/autolink.js @@ -1,12 +1,15 @@ jQuery.fn.autolink = function() { - return this.find('*').contents().filter(function () { return this.nodeType === 3; }).each(function() { - var re = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+:=&;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g; - $(this).each(function() { - $(this).replaceWith( - $("").html( - this.nodeValue.replace(re, "$1") - ) - ); + var re = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+:=&;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g; + return this.find('*').contents() + .filter(function () { return this.nodeType === 3; }) + .each(function() { + $(this).each(function() { + if (re.test($(this).text())) + $(this).replaceWith( + $("").html( + this.nodeValue.replace(re, "$1") + ) + ); + }); }); - }); }; \ No newline at end of file