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.

postprocess: Set up new loop for message embeds.

Karl Stolleyb7b409002e55
diff --git a/web/src/postprocess_content.ts b/web/src/postprocess_content.ts
index 946188a0f16..e90077764a6 100644
--- a/web/src/postprocess_content.ts
+++ b/web/src/postprocess_content.ts
@@ -26,6 +26,18 @@ export function postprocess_content(html: string): string {
ol.style.setProperty("counter-reset", `count ${list_start - 1}`);
}
+ // Here we're setting up better processing of message embeds;
+ // In the future, we will be able to write logic here to permit
+ // recipients to remove embeds on a per-message basis.
+ // We want to do this processing up front, so that embeds benefit
+ // from other processing below for links and images
+ for (const message_embed of template.content.querySelectorAll(".message_embed")) {
+ const message_embed_title_link = message_embed.querySelector(".message_embed_title a");
+ // Add a class to the anchor tag on embed-title links for easier
+ // reference from CSS
+ message_embed_title_link?.classList.add("message-embed-title-link");
+ }
+
for (const elt of template.content.querySelectorAll("a")) {
// Ensure that all external links have target="_blank"
// rel="opener noreferrer". This ensures that external links
@@ -97,11 +109,6 @@ export function postprocess_content(html: string): string {
["", legacy_title].includes(elt.title) ? title : `${title}\n${elt.title}`,
);
}
-
- // Add a class to the anchor tag on
- if (elt.parentElement?.classList.contains("message_embed_title")) {
- elt.classList.add("message-embed-title-link");
- }
}
for (const message_media_wrapper of template.content.querySelectorAll(
diff --git a/web/tests/postprocess_content.test.cjs b/web/tests/postprocess_content.test.cjs
index 728c150fbba..3952cdee5a0 100644
--- a/web/tests/postprocess_content.test.cjs
+++ b/web/tests/postprocess_content.test.cjs
@@ -81,7 +81,7 @@ run_test("postprocess_media_and_embeds", () => {
'<a class="message_embed_image" href="https://example.com/about" style="background-image: url(&quot;https://example.com/preview.jpeg&quot;)" target="_blank" rel="noopener noreferrer" title="https://example.com/about"></a>' +
'<div class="data-container">' +
'<div class="message_embed_title">' +
- '<a href="https://example.com/about" target="_blank" rel="noopener noreferrer" title="https://example.com/about" class="message-embed-title-link">About us</a>' +
+ '<a href="https://example.com/about" class="message-embed-title-link" target="_blank" rel="noopener noreferrer" title="https://example.com/about">About us</a>' +
"</div>" +
'<div class="message_embed_description">All about us.</div>' +
"</div>" +