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

This also adds test cases to test the local rendering of
user group mention in blockquotes.
This commit is contained in:
akshatdalton 2021-05-19 19:38:28 +00:00 committed by Tim Abbott
parent e50d189191
commit bf96d7eae8
2 changed files with 25 additions and 0 deletions

View File

@ -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", () => {

View File

@ -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