fix username lookup regex for mentions
This commit is contained in:
parent
1375954fbc
commit
dd9ea50456
|
@ -142,13 +142,13 @@ Discourse.Markdown = {
|
||||||
converter.hooks.chain("postConversion", function(text) {
|
converter.hooks.chain("postConversion", function(text) {
|
||||||
if (!text) return "";
|
if (!text) return "";
|
||||||
|
|
||||||
// don't to mention voodoo in pres
|
// don't do @username mentions inside <pre> blocks
|
||||||
text = text.replace(/<pre>([\s\S]*@[\s\S]*)<\/pre>/gi, function(wholeMatch, inner) {
|
text = text.replace(/<pre>([\s\S]*@[\s\S]*)<\/pre>/gi, function(wholeMatch, inner) {
|
||||||
return "<pre>" + (inner.replace(/@/g, '@')) + "</pre>";
|
return "<pre>" + (inner.replace(/@/g, '@')) + "</pre>";
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add @mentions of names
|
// add @username mentions, if valid; must be bounded on left and right by non-word characters
|
||||||
text = text.replace(/([\s\t>,:'|";\]])(@[A-Za-z0-9_-|\.]*[A-Za-z0-9_-|]+)(?=[\s\t<\!:|;',"\?\.])/g, function(x, pre, name) {
|
text = text.replace(/(\W)(@[A-Za-z0-9][A-Za-z0-9_]{2,14})(?=\W)/g, function(x, pre, name) {
|
||||||
if (mentionLookup(name.substr(1))) {
|
if (mentionLookup(name.substr(1))) {
|
||||||
return pre + "<a href='" + Discourse.getURL("/users/") + (name.substr(1).toLowerCase()) + "' class='mention'>" + name + "</a>";
|
return pre + "<a href='" + Discourse.getURL("/users/") + (name.substr(1).toLowerCase()) + "' class='mention'>" + name + "</a>";
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue