diff --git a/app/assets/javascripts/discourse/dialects/autolink_dialect.js b/app/assets/javascripts/discourse/dialects/autolink_dialect.js index f3c8c10e6f5..d231089cd92 100644 --- a/app/assets/javascripts/discourse/dialects/autolink_dialect.js +++ b/app/assets/javascripts/discourse/dialects/autolink_dialect.js @@ -10,7 +10,6 @@ var urlReplacerArgs = { var url = matches[1], displayUrl = url; - // Don't autolink a markdown link to something if (url.match(/\]\[\d$/)) { return; } diff --git a/app/assets/javascripts/discourse/dialects/mention_dialect.js b/app/assets/javascripts/discourse/dialects/mention_dialect.js index 0e13d02637c..400e8edfa80 100644 --- a/app/assets/javascripts/discourse/dialects/mention_dialect.js +++ b/app/assets/javascripts/discourse/dialects/mention_dialect.js @@ -20,3 +20,20 @@ Discourse.Dialect.inlineRegexp({ } }); +// We have to prune @mentions that are within links. +Discourse.Dialect.on("parseNode", function(event) { + var node = event.node, + path = event.path; + + if (node[1] && node[1]["class"] === 'mention') { + var parent = path[path.length - 1]; + // If the parent is an 'a', remove it + if (parent && parent[0] === 'a') { + var username = node[2]; + node.length = 0; + node[0] = "__RAW"; + node[1] = username; + } + } + +}); diff --git a/test/javascripts/lib/markdown_test.js b/test/javascripts/lib/markdown_test.js index 87d891ae219..9ca8307f85a 100644 --- a/test/javascripts/lib/markdown_test.js +++ b/test/javascripts/lib/markdown_test.js @@ -185,6 +185,14 @@ test("Mentions", function() { "

Hello @sam

", "translates mentions to links"); + cooked("[@codinghorror](https://twitter.com/codinghorror)", + "

@codinghorror

", + "it doesn't do mentions within links"); + + cookedOptions("[@codinghorror](https://twitter.com/codinghorror)", alwaysTrue, + "

@codinghorror

", + "it doesn't do link mentions within links"); + cooked("Hello @EvilTrout", "

Hello @EvilTrout

", "adds a mention class"); cooked("robin@email.host", "

robin@email.host

", "won't add mention class to an email address"); cooked("hanzo55@yahoo.com", "

hanzo55@yahoo.com

", "won't be affected by email addresses that have a number before the @ symbol");