FIX: @mentions within backticks followed by proper @mentions.
This commit is contained in:
parent
32655e9dad
commit
6fe0d29a01
|
@ -30,31 +30,52 @@ Discourse.Dialect.on("register", function(event) {
|
||||||
if (block.match(/^ {3}/)) { return; }
|
if (block.match(/^ {3}/)) { return; }
|
||||||
if (block.match(/^\>/)) { return; }
|
if (block.match(/^\>/)) { return; }
|
||||||
|
|
||||||
var pushIt = function(p) { result.push(p) };
|
var pushIt = function(p) { result.push(p) },
|
||||||
|
backtickCount = 0,
|
||||||
|
dirty = false;
|
||||||
|
|
||||||
while (m = pattern.exec(remaining)) {
|
while (m = pattern.exec(remaining)) {
|
||||||
result = result || ['p'];
|
result = result || ['p'];
|
||||||
|
|
||||||
var username = m[2],
|
var username = m[2],
|
||||||
usernameIndex = remaining.indexOf(username),
|
usernameIndex = remaining.indexOf(username),
|
||||||
before = remaining.slice(0, usernameIndex);
|
before = remaining.slice(0, usernameIndex),
|
||||||
|
prevBacktickCount = backtickCount;
|
||||||
|
|
||||||
// Break out if there is an uneven amount of backticks before
|
|
||||||
var backtickCount = before.split('`').length - 1;
|
|
||||||
if ((backtickCount % 2) === 1) { return; }
|
|
||||||
|
|
||||||
pattern.lastIndex = 0;
|
pattern.lastIndex = 0;
|
||||||
|
backtickCount = prevBacktickCount + (before.split('`').length - 1);
|
||||||
|
var dontMention = ((backtickCount % 2) === 1);
|
||||||
|
|
||||||
|
if (dontMention) {
|
||||||
|
before = before + username;
|
||||||
remaining = remaining.slice(usernameIndex + username.length);
|
remaining = remaining.slice(usernameIndex + username.length);
|
||||||
|
|
||||||
|
var nextMention = remaining.indexOf("@");
|
||||||
|
if (nextMention !== -1) {
|
||||||
|
before = before + remaining.slice(0, nextMention);
|
||||||
|
backtickCount = prevBacktickCount + (before.split('`').length - 1);
|
||||||
|
remaining = remaining.slice(nextMention);
|
||||||
|
this.processInline(before).forEach(pushIt);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
remaining = remaining.slice(usernameIndex + username.length);
|
||||||
|
}
|
||||||
|
|
||||||
if (before) {
|
if (before) {
|
||||||
this.processInline(before).forEach(pushIt);
|
this.processInline(before).forEach(pushIt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dontMention) {
|
||||||
if (mentionLookup(username.substr(1))) {
|
if (mentionLookup(username.substr(1))) {
|
||||||
result.push(['a', {'class': 'mention', href: Discourse.getURL("/users/") + username.substr(1).toLowerCase()}, username]);
|
result.push(['a', {'class': 'mention', href: Discourse.getURL("/users/") + username.substr(1).toLowerCase()}, username]);
|
||||||
} else {
|
} else {
|
||||||
result.push(['span', {'class': 'mention'}, username]);
|
result.push(['span', {'class': 'mention'}, username]);
|
||||||
}
|
}
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (remaining && remaining.match(/\n/)) {
|
if (remaining && remaining.match(/\n/)) {
|
||||||
next.unshift(MD.mk_block(remaining));
|
next.unshift(MD.mk_block(remaining));
|
||||||
|
@ -62,7 +83,7 @@ Discourse.Dialect.on("register", function(event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (dirty && result) {
|
||||||
if (remaining.length) {
|
if (remaining.length) {
|
||||||
this.processInline(remaining).forEach(pushIt);
|
this.processInline(remaining).forEach(pushIt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,6 +144,10 @@ test("Mentions", function() {
|
||||||
"<p>don't <code>@mention</code></p>",
|
"<p>don't <code>@mention</code></p>",
|
||||||
"Does not mention in an inline code block");
|
"Does not mention in an inline code block");
|
||||||
|
|
||||||
|
cooked("Yes `@this` should be code @eviltrout",
|
||||||
|
"<p>Yes <code>@this</code> should be code <span class=\"mention\">@eviltrout</span></p>",
|
||||||
|
"Does not mention in an inline code block");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Oneboxing", function() {
|
test("Oneboxing", function() {
|
||||||
|
|
Loading…
Reference in New Issue