mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 19:01:52 +08:00
FIX: @mentions should not be processed within links
This commit is contained in:
parent
19867c147b
commit
f51cbc8952
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue
Block a user