From c0a0865c09422f1c1d71216fc1c4ffd61bd35940 Mon Sep 17 00:00:00 2001 From: abhijitca Date: Thu, 27 Jun 2019 21:54:51 +0530 Subject: [PATCH 1/2] Fix the link issue which ends with 's' --- src/url.js | 18 +++++++++++++----- test/fixtures/url/default.txt | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/url.js b/src/url.js index c2ff0be..66f7339 100644 --- a/src/url.js +++ b/src/url.js @@ -15,13 +15,21 @@ function fixUrlsEndingInAParen(canidate) { function replaceUrlTextWithAutoLinkUrl(text) { const urlMatcher = /([a-z-_.:]+:\/\/\S+[^)\W]-?\/?)/ig; - const firstPass = text.replace(urlMatcher, "<$1>"); + var urlSMatcher = "([^>]+)\>s+$"; + var firstPass = text.replace(urlMatcher, "<$1>"); + var sequenceOfString = ""; + + if(firstPass.match(urlSMatcher)) { + var index = firstPass.lastIndexOf('>'); + sequenceOfString = firstPass.substring(index + 1, firstPass.length) + } 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 <> + .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"+sequenceOfString+">"); // Fix for URLs ended with 's' } 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 From 2502b6f9a277d2bb38a8e3a6bdc46be40e74ca67 Mon Sep 17 00:00:00 2001 From: abhijitca Date: Sat, 29 Jun 2019 11:36:20 +0530 Subject: [PATCH 2/2] Added check for chrome --- src/url.js | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/url.js b/src/url.js index 66f7339..e26dc95 100644 --- a/src/url.js +++ b/src/url.js @@ -14,22 +14,50 @@ function fixUrlsEndingInAParen(canidate) { } function replaceUrlTextWithAutoLinkUrl(text) { - const urlMatcher = /([a-z-_.:]+:\/\/\S+[^)\W]-?\/?)/ig; + var urlMatcher = /([a-z-_.:]+:\/\/\S+[^)\W]-?\/?)/ig; var urlSMatcher = "([^>]+)\>s+$"; var firstPass = text.replace(urlMatcher, "<$1>"); - var sequenceOfString = ""; - - if(firstPass.match(urlSMatcher)) { + var sSubstring = ""; + var formattedString = ""; + + var isChrome = checkForChrome() + if(firstPass.match(urlSMatcher) && isChrome) { var index = firstPass.lastIndexOf('>'); - sequenceOfString = firstPass.substring(index + 1, firstPass.length) + 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 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"+sequenceOfString+">"); // Fix for URLs ended with 's' + 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) {