diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js index 7363723115..b00bf62f15 100644 --- a/frontend_tests/node_tests/markdown.js +++ b/frontend_tests/node_tests/markdown.js @@ -424,6 +424,16 @@ test("marked", () => { expected: '

User group mention: @Backend
\nUser group silent mention: hamletcharacters

', }, + { + input: "> User group mention in quote: @*backend*\n\n> Another user group mention in quote: @*hamletcharacters*", + expected: + '
\n

User group mention in quote: Backend

\n
\n
\n

Another user group mention in quote: hamletcharacters

\n
', + }, + { + input: "```quote\nUser group mention in quote: @*backend*\n```\n\n```quote\nAnother user group mention in quote: @*hamletcharacters*\n```", + expected: + '
\n

User group mention in quote: Backend

\n
\n
\n

Another user group mention in quote: hamletcharacters

\n
', + }, // Test only those linkifiers which don't return True for // `contains_backend_only_syntax()`. Those which return True // are tested separately. @@ -740,6 +750,11 @@ test("message_flags", () => { message = {topic: "No links here", raw_content: input}; markdown.apply_markdown(message); assert.equal(message.mentioned, false); + + input = "> test @*hamletcharacters*"; + message = {topic: "No links here", raw_content: input}; + markdown.apply_markdown(message); + assert.equal(message.mentioned, false); }); test("backend_only_linkifiers", () => { diff --git a/static/js/markdown.js b/static/js/markdown.js index 30f81011e3..67a57a66ea 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -224,6 +224,16 @@ export function apply_markdown(message) { match = match.replace(/>@/g, ">"); return match; }); + + // Silence quoted user group mentions. + const user_group_re = + /]*user-group-mention[^>]*data-user-group-id="\d+"[^>]*>@/gm; + quote = quote.replace(user_group_re, (match) => { + match = match.replace(/"user-group-mention"/g, '"user-group-mention silent"'); + match = match.replace(/>@/g, ">"); + return match; + }); + // In most cases, if you are being mentioned in the message you're quoting, you wouldn't // mention yourself outside of the blockquote (and, above it). If that you do that, the // following mentioned status is false; the backend rendering is authoritative and the