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/mention_dialect.js

23 lines
693 B
JavaScript

/**
Supports Discourse's 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.
**/
Discourse.Dialect.inlineRegexp({
start: '@',
matcher: /^(@[A-Za-z0-9][A-Za-z0-9_]{2,14})/m,
wordBoundary: true,
emitter: function(matches) {
var username = matches[1],
mentionLookup = this.dialect.options.mentionLookup;
if (mentionLookup && mentionLookup(username.substr(1))) {
return ['a', {'class': 'mention', href: Discourse.getURL("/users/") + username.substr(1).toLowerCase()}, username];
} else {
return ['span', {'class': 'mention'}, username];
}
}
});