Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Handle pasting new-style inline image elements.
Karl Stolleyc2f9e9ca165d
diff --git a/web/src/compose_paste.ts b/web/src/compose_paste.tsindex 9540046d781..a3a9939cccf 100644--- a/web/src/compose_paste.ts+++ b/web/src/compose_paste.ts@@ -39,10 +39,26 @@ function image_to_zulip_markdown(// For Zulip's custom emojireturn node.getAttribute("alt") ?? "";}- const src = node.getAttribute("src") ?? node.getAttribute("href") ?? "";- const title = deduplicate_newlines(node.getAttribute("title") ?? "");- // Using Zulip's link like syntax for images- return src ? "[" + title + "](" + src + ")" : (node.getAttribute("alt") ?? "");+ // For inline images presented in Markdown syntax, we need+ // to grab the `data-original-src` attribute, rather than+ // the thumbnailed image referenced on the `src` attribute+ const src =+ node.getAttribute("data-original-src") ??+ node.getAttribute("src") ??+ node.getAttribute("href") ??+ "";+ // For the label, we prioritize the alt attribute, which will be+ // present on both Zulip and third-party Markdown images, but use+ // title as a fallback, since older-style Zulip image previews+ // only set title.+ let alt = "";+ if (node.classList.contains("inline-image")) {+ alt = node.getAttribute("alt") ?? "";+ } else {+ alt = deduplicate_newlines(node.getAttribute("title") ?? "");+ }+ // Use Markdown syntax for images+ return src ? "" : (node.getAttribute("alt") ?? "");}// Returns the count of valid text nodes in the tree.@@ -475,6 +491,7 @@ export function paste_handler_converter(return image_to_zulip_markdown(content, node.firstElementChild);},});+turndownService.addRule("images", {filter: "img",