mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 05:29:17 -06:00
234694b50f
This adds the markdown.it engine to Discourse. https://github.com/markdown-it/markdown-it As the migration is going to take a while the new engine is default disabled. To enable it you must change the hidden site setting: enable_experimental_markdown_it. This commit is a squash of many other commits, it also includes some improvements to autospec (ability to run plugins), and a dev dependency on the og gem for html normalization.
28 lines
890 B
JavaScript
28 lines
890 B
JavaScript
// This addition handles auto linking of text. When included, it will parse out links and create
|
|
// `<a href>`s for them.
|
|
|
|
const urlReplacerArgs = {
|
|
matcher: /^((?:https?:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.])(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»“”‘’\s]))/,
|
|
spaceOrTagBoundary: true,
|
|
|
|
emitter(matches) {
|
|
const url = matches[1];
|
|
let href = 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/)) { href = "http://" + url; }
|
|
return ['a', { href }, url];
|
|
}
|
|
};
|
|
|
|
export function setup(helper) {
|
|
if (helper.markdownIt) { return; }
|
|
helper.inlineRegexp(_.merge({start: 'http'}, urlReplacerArgs));
|
|
helper.inlineRegexp(_.merge({start: 'www'}, urlReplacerArgs));
|
|
}
|