diff --git a/app/assets/javascripts/discourse/dialects/mention_dialect.js b/app/assets/javascripts/discourse/dialects/mention_dialect.js index b90b835ad57..7caced75ffb 100644 --- a/app/assets/javascripts/discourse/dialects/mention_dialect.js +++ b/app/assets/javascripts/discourse/dialects/mention_dialect.js @@ -39,6 +39,10 @@ Discourse.Dialect.on("register", function(event) { usernameIndex = remaining.indexOf(username), before = remaining.slice(0, usernameIndex); + // 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; remaining = remaining.slice(usernameIndex + username.length); diff --git a/test/javascripts/components/markdown_test.js b/test/javascripts/components/markdown_test.js index b272d4e4d9b..b4757545d38 100644 --- a/test/javascripts/components/markdown_test.js +++ b/test/javascripts/components/markdown_test.js @@ -132,6 +132,18 @@ test("Mentions", function() { "
", "does mentions properly with trailing text within a simple quote"); + cooked("`code` is okay before @mention", + "foo bar baz @eviltrout
ohmagerd\nlook at this
code
is okay before @mention
@mention is okay before code
don't @mention