Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

markdown: Add support for local rendering of user group mention in quote.

akshatdaltonbf96d7eae8cf
diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js
index 73637231157..b00bf62f155 100644
--- a/frontend_tests/node_tests/markdown.js
+++ b/frontend_tests/node_tests/markdown.js
@@ -424,6 +424,16 @@ test("marked", () => {
expected:
'<p>User group mention: <span class="user-group-mention" data-user-group-id="2">@Backend</span><br>\nUser group silent mention: <span class="user-group-mention silent" data-user-group-id="1">hamletcharacters</span></p>',
},
+ {
+ input: "> User group mention in quote: @*backend*\n\n> Another user group mention in quote: @*hamletcharacters*",
+ expected:
+ '<blockquote>\n<p>User group mention in quote: <span class="user-group-mention silent" data-user-group-id="2">Backend</span></p>\n</blockquote>\n<blockquote>\n<p>Another user group mention in quote: <span class="user-group-mention silent" data-user-group-id="1">hamletcharacters</span></p>\n</blockquote>',
+ },
+ {
+ input: "```quote\nUser group mention in quote: @*backend*\n```\n\n```quote\nAnother user group mention in quote: @*hamletcharacters*\n```",
+ expected:
+ '<blockquote>\n<p>User group mention in quote: <span class="user-group-mention silent" data-user-group-id="2">Backend</span></p>\n</blockquote>\n<blockquote>\n<p>Another user group mention in quote: <span class="user-group-mention silent" data-user-group-id="1">hamletcharacters</span></p>\n</blockquote>',
+ },
// 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 30f81011e31..67a57a66ead 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 =
+ /<span[^>]*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