diff --git a/src/url.js b/src/url.js index c2ff0be..e26dc95 100644 --- a/src/url.js +++ b/src/url.js @@ -14,14 +14,50 @@ function fixUrlsEndingInAParen(canidate) { } function replaceUrlTextWithAutoLinkUrl(text) { - const urlMatcher = /([a-z-_.:]+:\/\/\S+[^)\W]-?\/?)/ig; - const firstPass = text.replace(urlMatcher, "<$1>"); - - return fixUrlsEndingInAParen(firstPass) - .replace(/(<_([^>]+)_>)/, "_[$2]($2)_") // Fix for URLs included in __ - .replace(/\[([^\]]+)\]\(<([^>]+)>\)/, "[$1]($2)") // Fix for URLs already in markdown syntax []() - .replace(/<(onenote:[^>]+)>/, "[$1]($1)") // Fix for onenote urls - .replace(/<<([^>]+)>>/ig, "<$1>"); // Fix for URLs already surrounded by <> + var urlMatcher = /([a-z-_.:]+:\/\/\S+[^)\W]-?\/?)/ig; + var urlSMatcher = "([^>]+)\>s+$"; + var firstPass = text.replace(urlMatcher, "<$1>"); + var sSubstring = ""; + var formattedString = ""; + + var isChrome = checkForChrome() + if(firstPass.match(urlSMatcher) && isChrome) { + var index = firstPass.lastIndexOf('>'); + sSubstring = firstPass.substring(index+1, firstPass.length) + } + + formattedString = fixUrlsEndingInAParen(firstPass) + .replace(/(<_([^>]+)_>)/, "_[$2]($2)_") // Fix for URLs included in __ + .replace(/\[([^\]]+)\]\(<([^>]+)>\)/, "[$1]($2)") // Fix for URLs already in markdown syntax []() + .replace(/<(onenote:[^>]+)>/, "[$1]($1)") // Fix for onenote urls + .replace(/<<([^>]+)>>/ig, "<$1>") // Fix for URLs already surrounded by <> + .replace(/<([^>]+)\>s+$/, "<$1"+sSubstring+">"); + + if(isChrome) { + formattedString = fixUrlsEndingInAParen(firstPass).replace(/<([^>]+)\>s+$/, "<$1"+sSubstring+">") + } + + return formattedString; +} + +function checkForChrome() { + var isChromium = window.chrome; + var winNav = window.navigator; + var vendorName = winNav.vendor; + var isOpera = typeof window.opr !== "undefined"; + var isIEedge = winNav.userAgent.indexOf("Edge") > -1; + + if( + isChromium !== null && + typeof isChromium !== "undefined" && + vendorName === "Google Inc." && + isOpera === false && + isIEedge === false + ) { + return true; + } else { + return false; + } } function dealWithCodeBlock(text) { diff --git a/test/fixtures/url/default.txt b/test/fixtures/url/default.txt index c8b8b9b..e5892e9 100644 --- a/test/fixtures/url/default.txt +++ b/test/fixtures/url/default.txt @@ -12,6 +12,21 @@ http://flowdock.com

http://flowdock.com

. +works with simple urls +. +http://flowdock.com/s +. +

http://flowdock.com/s

+. + + +works with simple urls +. +http://flowdock.com/sssss +. +

http://flowdock.com/sssss

+. + works with text before the url . baz http://flowdock.com