Open kxmbrian opened 5 years ago
Would be happy to do a PR for this if you could point me in the right direction
Running into the same issue with java file names which end with standard TLD like:
/home/data/httpd/download.eclipse.org
where the download.eclipse.org
is being auto-linked.
I think maybe if a URL is preceded by a /
it is likely a file path and should not be auto-linked.
Unsure what cases I may be missing though 🤷♂
Hey guys. Yeah, it's tough to say whether we should always prevent linking when there is a slash in front of the url. I'll have to think about this a bit more, but in the meantime you can try using the replaceFn as a workaround. Try something like this:
Autolinker.link(inputText, {
replaceFn: function(match) {
if (match.getType() === 'url') {
var previousChar = inputText.charAt(match.getOffset() - 1);
if (previousChar === '/') {
return false; // don't autolink this match
}
}
}
});
Solid suggestion, thank you!
Just a heads up if you consider adding this rule: on my end I skip the match if the url is preceded by /
and is not prefixed by www.
or common protocol like http://
.
So I'll match on:
link/between/slashes/www.example.com/
I am a link/http://nytimes.com
But not:
/this/is/probably/a/file/download.eclipse.org
/path/to/script/file.sh
Not sure about the full breadth of use cases, but would it be feasible not to match filenames while still matching TLDs?
One solution is to enforce that all URL matches are either at the start of a line or are preceded by whitespace, but from #159, it seems that that might not fit everyone's needs.