Skip to content
This repository was archived by the owner on Jul 24, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 _<url>_
.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 _<url>_
.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) {
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/url/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ http://flowdock.com
<p><a href="http://flowdock.com">http://flowdock.com</a></p>
.

works with simple urls
.
http://flowdock.com/s
.
<p><a href="http://flowdock.com/s">http://flowdock.com/s</a></p>
.


works with simple urls
.
http://flowdock.com/sssss
.
<p><a href="http://flowdock.com/sssss">http://flowdock.com/sssss</a></p>
.

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