This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/dialects/autolink_dialect.js
2015-02-06 00:41:38 -08:00

26 lines
857 B
JavaScript

/**
This addition handles auto linking of text. When included, it will parse out links and create
a hrefs for them.
**/
var urlReplacerArgs = {
matcher: /^((?:https?:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.])(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»“”‘’\s]))/,
spaceOrTagBoundary: true,
emitter: function(matches) {
var url = matches[1],
displayUrl = url;
// Don't autolink a markdown link to something
if (url.match(/\]\[\d$/)) { return; }
// If we improperly caught a markdown link abort
if (url.match(/\(http/)) { return; }
if (url.match(/^www/)) { url = "http://" + url; }
return ['a', {href: url}, displayUrl];
}
};
Discourse.Dialect.inlineRegexp(_.merge({start: 'http'}, urlReplacerArgs));
Discourse.Dialect.inlineRegexp(_.merge({start: 'www'}, urlReplacerArgs));