FIX: @mentions should not be processed within links

This commit is contained in:
Robin Ward 2014-05-06 17:48:11 -04:00
parent 19867c147b
commit f51cbc8952
3 changed files with 25 additions and 1 deletions

View File

@ -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; }

View File

@ -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;
}
}
});

View File

@ -185,6 +185,14 @@ test("Mentions", function() {
"<p>Hello <a class=\"mention\" href=\"/users/sam\">@sam</a></p>",
"translates mentions to links");
cooked("[@codinghorror](https://twitter.com/codinghorror)",
"<p><a href=\"https://twitter.com/codinghorror\">@codinghorror</a></p>",
"it doesn't do mentions within links");
cookedOptions("[@codinghorror](https://twitter.com/codinghorror)", alwaysTrue,
"<p><a href=\"https://twitter.com/codinghorror\">@codinghorror</a></p>",
"it doesn't do link mentions within links");
cooked("Hello @EvilTrout", "<p>Hello <span class=\"mention\">@EvilTrout</span></p>", "adds a mention class");
cooked("robin@email.host", "<p>robin@email.host</p>", "won't add mention class to an email address");
cooked("hanzo55@yahoo.com", "<p>hanzo55@yahoo.com</p>", "won't be affected by email addresses that have a number before the @ symbol");