Merge pull request #851 from ZogStriP/fix-user-mention-when-there-are-multiple-code-blocks
FIX: @username mentions when there are multiple code blocks in a post.
This commit is contained in:
commit
1201ba9920
|
@ -143,8 +143,8 @@ Discourse.Markdown = {
|
|||
if (!text) return "";
|
||||
|
||||
// don't do @username mentions inside <pre> or <code> blocks
|
||||
text = text.replace(/<(pre|code)>([\s\S]*?@[\s\S]*?)<\/(pre|code)>/gi, function(wholeMatch, m1, m2, m3) {
|
||||
return "<" + m1 + ">" + (m2.replace(/@/g, '@')) + "</" + m3 + ">";
|
||||
text = text.replace(/<(pre|code)>([\s\S](?!<(pre|code)>))*?@([\s\S](?!<(pre|code)>))*?<\/(pre|code)>/gi, function(m) {
|
||||
return m.replace(/@/g, '@');
|
||||
});
|
||||
|
||||
// add @username mentions, if valid; must be bounded on left and right by non-word characters
|
||||
|
|
|
@ -92,6 +92,14 @@ describe("Discourse.Markdown", function() {
|
|||
expect(cook("@EvilTrout yo")).toBe("<p><span class='mention'>@EvilTrout</span> yo</p>");
|
||||
});
|
||||
|
||||
it("doesn't do @username mentions inside <pre> or <code> blocks", function() {
|
||||
expect(cook("`@EvilTrout yo`")).toBe("<p><code>@EvilTrout yo</code></p>");
|
||||
});
|
||||
|
||||
it("deals correctly with multiple <code> blocks", function() {
|
||||
expect(cook("`evil` @EvilTrout `trout`")).toBe("<p><code>evil</code> <span class='mention'>@EvilTrout</span> <code>trout</code></p>");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("Oneboxing", function() {
|
||||
|
|
Loading…
Reference in New Issue