mirror of
https://github.com/zulip/zulip.git
synced 2025-10-25 00:53:56 +00:00
url_previews: Post-process embed links for performant CSS.
This commit is contained in:
@@ -211,6 +211,7 @@ js_rules = RuleList(
|
|||||||
"description": "Avoid using the `style=` attribute; we prefer styling in CSS files",
|
"description": "Avoid using the `style=` attribute; we prefer styling in CSS files",
|
||||||
"exclude": {
|
"exclude": {
|
||||||
"web/tests/compose_paste.test.cjs",
|
"web/tests/compose_paste.test.cjs",
|
||||||
|
"web/tests/postprocess_content.test.cjs",
|
||||||
},
|
},
|
||||||
"good_lines": ["#my-style {color: blue;}", "const style =", 'some_style = "test"'],
|
"good_lines": ["#my-style {color: blue;}", "const style =", 'some_style = "test"'],
|
||||||
"bad_lines": ['<p style="color: blue;">Foo</p>', 'style = "color: blue;"'],
|
"bad_lines": ['<p style="color: blue;">Foo</p>', 'style = "color: blue;"'],
|
||||||
|
|||||||
@@ -84,6 +84,11 @@ export function postprocess_content(html: string): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a class to the anchor tag on
|
||||||
|
if (elt.parentElement?.classList.contains("message_embed_title")) {
|
||||||
|
elt.classList.add("message-embed-title-link");
|
||||||
|
}
|
||||||
|
|
||||||
if (elt.parentElement?.classList.contains("message_inline_image")) {
|
if (elt.parentElement?.classList.contains("message_inline_image")) {
|
||||||
// For inline images we want to handle the tooltips explicitly, and disable
|
// For inline images we want to handle the tooltips explicitly, and disable
|
||||||
// the browser's built in handling of the title attribute.
|
// the browser's built in handling of the title attribute.
|
||||||
|
|||||||
@@ -732,7 +732,7 @@
|
|||||||
color: var(--color-markdown-link-hover);
|
color: var(--color-markdown-link-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
.message-embed-title-link {
|
||||||
/* Line-clamp lines seem to have a small
|
/* Line-clamp lines seem to have a small
|
||||||
interline area that's not clickable
|
interline area that's not clickable
|
||||||
unless we set the anchor to display as
|
unless we set the anchor to display as
|
||||||
|
|||||||
@@ -34,6 +34,15 @@ run_test("postprocess_content", () => {
|
|||||||
'<a class="" href="https://www.youtube.com/watch?v=tyKJueEk0XM">' +
|
'<a class="" href="https://www.youtube.com/watch?v=tyKJueEk0XM">' +
|
||||||
'<img src="https://i.ytimg.com/vi/tyKJueEk0XM/default.jpg">' +
|
'<img src="https://i.ytimg.com/vi/tyKJueEk0XM/default.jpg">' +
|
||||||
"</a>" +
|
"</a>" +
|
||||||
|
"</div>" +
|
||||||
|
'<div class="message_embed">' +
|
||||||
|
'<a class="message_embed_image" href="https://example.com/about" style="background-image: url("https://example.com/preview.jpeg")"></a>' +
|
||||||
|
'<div class="data-container">' +
|
||||||
|
'<div class="message_embed_title">' +
|
||||||
|
'<a href="https://example.com/about">About us</a>' +
|
||||||
|
"</div>" +
|
||||||
|
'<div class="message_embed_description">All about us.</div>' +
|
||||||
|
"</div>" +
|
||||||
"</div>",
|
"</div>",
|
||||||
),
|
),
|
||||||
'<a href="http://example.com" target="_blank" rel="noopener noreferrer" title="http://example.com/">good</a> ' +
|
'<a href="http://example.com" target="_blank" rel="noopener noreferrer" title="http://example.com/">good</a> ' +
|
||||||
@@ -56,6 +65,15 @@ run_test("postprocess_content", () => {
|
|||||||
'<img src="https://i.ytimg.com/vi/tyKJueEk0XM/mqdefault.jpg" class="media-image-element" loading="lazy">' +
|
'<img src="https://i.ytimg.com/vi/tyKJueEk0XM/mqdefault.jpg" class="media-image-element" loading="lazy">' +
|
||||||
"</a>" +
|
"</a>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
|
"</div>" +
|
||||||
|
'<div class="message_embed">' +
|
||||||
|
'<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" class="message-embed-title-link" title="https://example.com/about">About us</a>' +
|
||||||
|
"</div>" +
|
||||||
|
'<div class="message_embed_description">All about us.</div>' +
|
||||||
|
"</div>" +
|
||||||
"</div>",
|
"</div>",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user