mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
postprocess: Set up new loop for message embeds.
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -81,7 +81,7 @@ run_test("postprocess_media_and_embeds", () => {
|
||||
'<a class="message_embed_image" href="https://example.com/about" style="background-image: url("https://example.com/preview.jpeg")" 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>" +
|
||||
|
||||
Reference in New Issue
Block a user