mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08: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.
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
/**
|
|
Supports our custom @mention syntax for calling out a user in a post.
|
|
It will add a special class to them, and create a link if the user is found in a
|
|
local map.
|
|
**/
|
|
export function setup(helper) {
|
|
|
|
if (helper.markdownIt) { return; }
|
|
|
|
// We have to prune @mentions that are within links.
|
|
helper.onParseNode(event => {
|
|
const node = event.node,
|
|
path = event.path;
|
|
|
|
if (node[1] && node[1]["class"] === 'mention') {
|
|
const parent = path[path.length - 1];
|
|
|
|
// If the parent is an 'a', remove it
|
|
if (parent && parent[0] === 'a') {
|
|
const name = node[2];
|
|
node.length = 0;
|
|
node[0] = "__RAW";
|
|
node[1] = name;
|
|
}
|
|
}
|
|
});
|
|
|
|
helper.inlineRegexp({
|
|
start: '@',
|
|
// NOTE: since we can't use SiteSettings here (they loads later in process)
|
|
// we are being less strict to account for more cases than allowed
|
|
matcher: /^@(\w[\w.-]{0,59})\b/i,
|
|
wordBoundary: true,
|
|
|
|
emitter(matches) {
|
|
const mention = matches[0].trim();
|
|
const name = matches[1];
|
|
const opts = helper.getOptions();
|
|
const mentionLookup = opts.mentionLookup;
|
|
|
|
const type = mentionLookup && mentionLookup(name);
|
|
if (type === "user") {
|
|
return ['a', {'class': 'mention', href: opts.getURL("/u/") + name.toLowerCase()}, mention];
|
|
} else if (type === "group") {
|
|
return ['a', {'class': 'mention-group', href: opts.getURL("/groups/") + name}, mention];
|
|
} else {
|
|
return ['span', {'class': 'mention'}, mention];
|
|
}
|
|
}
|
|
});
|
|
}
|