Skip to content

Commit 0f27232

Browse files
committed
FIX: Support inline code blocks with @mentions in them.
1 parent 10bc24b commit 0f27232

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

app/assets/javascripts/discourse/dialects/mention_dialect.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Discourse.Dialect.on("register", function(event) {
3939
usernameIndex = remaining.indexOf(username),
4040
before = remaining.slice(0, usernameIndex);
4141

42+
// Break out if there is an uneven amount of backticks before
43+
var backtickCount = before.split('`').length - 1;
44+
if ((backtickCount % 2) === 1) { return; }
45+
4246
pattern.lastIndex = 0;
4347
remaining = remaining.slice(usernameIndex + username.length);
4448

test/javascripts/components/markdown_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ test("Mentions", function() {
132132
"<blockquote><p>foo bar baz <span class=\"mention\">@eviltrout</span></p><p> ohmagerd\nlook at this</p></blockquote>",
133133
"does mentions properly with trailing text within a simple quote");
134134

135+
cooked("`code` is okay before @mention",
136+
"<p><code>code</code> is okay before <span class=\"mention\">@mention</span></p>",
137+
"Does not mention in an inline code block");
138+
139+
cooked("@mention is okay before `code`",
140+
"<p><span class=\"mention\">@mention</span> is okay before <code>code</code></p>",
141+
"Does not mention in an inline code block");
142+
143+
cooked("don't `@mention`",
144+
"<p>don't <code>@mention</code></p>",
145+
"Does not mention in an inline code block");
146+
135147
});
136148

137149
test("Oneboxing", function() {

0 commit comments

Comments
 (0)