Skip to content

Commit

Permalink
FIX: Don't onebox @mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed Aug 24, 2013
1 parent 1ef9354 commit 20e8a8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/discourse/dialects/dialect.js
Expand Up @@ -5,7 +5,7 @@
To extend the dialect, you can register a handler, and you will receive an `event` object
with a handle to the markdown `Dialect` from Markdown.js that we are defining. Here's
a sample dialect that replaces all occurances of "evil trout" with a link that says
a sample dialect that replaces all occurrences of "evil trout" with a link that says
"EVIL TROUT IS AWESOME":
```javascript
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/discourse/dialects/onebox_dialect.js
Expand Up @@ -49,6 +49,9 @@ Discourse.Dialect.on("parseNode", function(event) {
return;
}

// We don't onebox mentions
if (node[1]['class'] === 'mention') { return; }

// Don't onebox links within a list
for (var i=0; i<path.length; i++) {
if (path[i][0] === 'li') { return; }
Expand Down
9 changes: 8 additions & 1 deletion test/javascripts/components/markdown_test.js
Expand Up @@ -116,7 +116,10 @@ test("Quotes", function() {
});

test("Mentions", function() {
cookedOptions("Hello @sam", { mentionLookup: (function() { return true; }) },

var alwaysTrue = { mentionLookup: (function() { return true; }) };

cookedOptions("Hello @sam", alwaysTrue,
"<p>Hello <a class=\"mention\" href=\"/users/sam\">@sam</a></p>",
"translates mentions to links");

Expand Down Expand Up @@ -162,6 +165,10 @@ test("Mentions", function() {
"<ol><li><p>this is a list</p></li><li><p>this is an <span class=\"mention\">@eviltrout</span> mention </p></li></ol>",
"it mentions properly in a list.");

cookedOptions("@eviltrout", alwaysTrue,
"<p><a class=\"mention\" href=\"/users/eviltrout\">@eviltrout</a></p>",
"it doesn't onebox mentions");

});

test("Oneboxing", function() {
Expand Down

0 comments on commit 20e8a8a

Please sign in to comment.