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: Silence user group mention inside blockquotes.

akshatdalton18203d8af381
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
index 448fb2edaae..d421e365d85 100644
--- a/zerver/lib/markdown/__init__.py
+++ b/zerver/lib/markdown/__init__.py
@@ -1708,6 +1708,8 @@ class BlockQuoteProcessor(markdown.blockprocessors.BlockQuoteProcessor):
def clean(self, line: str) -> str:
# Silence all the mentions inside blockquotes
line = mention.MENTIONS_RE.sub(lambda m: "@_**{}**".format(m.group("match")), line)
+ # Silence all the user group mentions inside blockquotes
+ line = mention.USER_GROUP_MENTIONS_RE.sub(lambda m: "@_*{}*".format(m.group("match")), line)
# And then run the upstream processor's code for removing the '>'
return super().clean(line)
diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py
index ca3bb5e9ebd..bea8815a414 100644
--- a/zerver/tests/test_markdown.py
+++ b/zerver/tests/test_markdown.py
@@ -2333,6 +2333,25 @@ class MarkdownTest(ZulipTestCase):
self.assertEqual(msg.mentions_user_group_ids, set())
+ def test_user_group_mention_in_quotes(self) -> None:
+ user_profile = self.example_user("othello")
+ msg = Message(sender=user_profile, sending_client=get_client("test"))
+ backend = self.create_user_group_for_test("backend")
+
+ def assert_silent_mention(content: str) -> None:
+ expected = (
+ "<blockquote>\n<p>"
+ f'<span class="user-group-mention silent" data-user-group-id="{backend.id}">backend</span>'
+ "</p>\n</blockquote>"
+ )
+ self.assertEqual(render_markdown(msg, content), expected)
+ self.assertEqual(msg.mentions_user_group_ids, set())
+
+ assert_silent_mention("> @*backend*")
+ assert_silent_mention("> @_*backend*")
+ assert_silent_mention("```quote\n@*backend*\n```")
+ assert_silent_mention("```quote\n@_*backend*\n```")
+
def test_stream_single(self) -> None:
denmark = get_stream("Denmark", get_realm("zulip"))
sender_user_profile = self.example_user("othello")