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 silent mention.
akshatdalton5bab65e82f99
diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.jsindex db464ea5f79..73637231157 100644--- a/frontend_tests/node_tests/markdown.js+++ b/frontend_tests/node_tests/markdown.js@@ -419,6 +419,11 @@ test("marked", () => {expected:'<blockquote>\n<p>Wildcard mention in quote: <span class="user-mention silent" data-user-id="*">all</span></p>\n</blockquote>\n<blockquote>\n<p>Another wildcard mention in quote: <span class="user-mention silent" data-user-id="*">all</span></p>\n</blockquote>',},+ {+ input: "User group mention: @*backend*\nUser group silent mention: @_*hamletcharacters*",+ 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>',+ },// Test only those linkifiers which don't return True for// `contains_backend_only_syntax()`. Those which return True// are tested separately.@@ -730,6 +735,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.jsindex 5336f4895df..042612dd738 100644--- a/static/js/markdown.js+++ b/static/js/markdown.js@@ -194,15 +194,25 @@ export function apply_markdown(message) {display_text,)}</span>`;},- groupMentionHandler(name) {+ groupMentionHandler(name, silently) {const group = helpers.get_user_group_from_name(name);if (group !== undefined) {- if (helpers.is_member_of_user_group(group.id, helpers.my_user_id())) {- message.mentioned = true;+ let display_text;+ let classes;+ if (silently) {+ display_text = group.name;+ classes = "user-group-mention silent";+ } else {+ display_text = "@" + group.name;+ classes = "user-group-mention";+ if (helpers.is_member_of_user_group(group.id, helpers.my_user_id())) {+ message.mentioned = true;+ }}- return `<span class="user-group-mention" data-user-group-id="${_.escape(++ return `<span class="${classes}" data-user-group-id="${_.escape(group.id,- )}">@${_.escape(group.name)}</span>`;+ )}">${_.escape(display_text)}</span>`;}return undefined;},diff --git a/static/third/marked/lib/marked.js b/static/third/marked/lib/marked.jsindex eebf3cb4291..5653376ccfe 100644--- a/static/third/marked/lib/marked.js+++ b/static/third/marked/lib/marked.js@@ -545,7 +545,7 @@ inline.zulip = merge({}, inline.breaks, {'[\u2000-\u206F]|[\u2300-\u27BF]|[\u2B00-\u2BFF]|' +'[\u3000-\u303F]|[\u3200-\u32FF])'),usermention: /^(@(_?)(?:\*\*([^\*]+)\*\*))/, // Match potentially multi-word string between @** **- groupmention: /^@\*([^\*]+)\*/, // Match multi-word string between @* *+ groupmention: /^@(_?)(?:\*([^\*]+)\*)/, // Match multi-word string between @* *stream_topic: /^#\*\*([^\*>]+)>([^\*]+)\*\*/,stream: /^#\*\*([^\*]+)\*\*/,tex: /^(\$\$([^\n_$](\\\$|[^\n$])*)\$\$(?!\$))\B/,@@ -750,7 +750,7 @@ InlineLexer.prototype.output = function(src) {// groupmention (Zulip)if (cap = this.rules.groupmention.exec(src)) {src = src.substring(cap[0].length);- out += this.groupmention(unescape(cap[1]), cap[0]);+ out += this.groupmention(unescape(cap[2]), cap[0], cap[1]);continue;}@@ -911,14 +911,14 @@ InlineLexer.prototype.usermention = function (username, orig, silent) {return orig;};-InlineLexer.prototype.groupmention = function (groupname, orig) {+InlineLexer.prototype.groupmention = function (groupname, orig, silent) {orig = escape(orig);if (typeof this.options.groupMentionHandler !== 'function'){return orig;}- var handled = this.options.groupMentionHandler(groupname);+ var handled = this.options.groupMentionHandler(groupname, silent === '_');if (handled !== undefined) {return handled;}