Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Always retain `ol` tag when pasting content enclosed by it.
N-Shar-ma24e811935058
diff --git a/web/src/copy_and_paste.js b/web/src/copy_and_paste.jsindex 4a37f6de7e3..038a078b10c 100644--- a/web/src/copy_and_paste.js+++ b/web/src/copy_and_paste.js@@ -319,9 +319,14 @@ export function paste_handler_converter(paste_html) {copied_html_fragment.childNodes.length === 1 &&copied_html_fragment.firstElementChild &&copied_html_fragment.firstElementChild.innerHTML;+ const outer_elements_to_retain = ["PRE", "OL"];// If the entire selection copied is within a single HTML element (like an- // `h1`), we don't want to retain its styling. We retain `pre` for code blocks.- if (copied_within_single_element && copied_html_fragment.firstElementChild.nodeName !== "PRE") {+ // `h1`), we don't want to retain its styling, except when it helps identify+ // the intended structure of the copied content (like `pre` and `ol`).+ if (+ copied_within_single_element &&+ !outer_elements_to_retain.includes(copied_html_fragment.firstElementChild.nodeName)+ ) {paste_html = copied_html_fragment.firstChild.innerHTML;}diff --git a/web/tests/copy_and_paste.test.js b/web/tests/copy_and_paste.test.jsindex 5d229454607..b4d211addc4 100644--- a/web/tests/copy_and_paste.test.js+++ b/web/tests/copy_and_paste.test.js@@ -51,15 +51,19 @@ run_test("paste_handler_converter", () => {"normal text [Contributing guide](https://zulip.readthedocs.io/en/latest/contributing/contributing.html)",);- // Numbered list item+ // Only numbered list (list style retained)input =- '<meta http-equiv="content-type" content="text/html; charset=utf-8"><span style="color: hsl(0, 0%, 0%); font-family: "Helvetica Neue", "Segoe UI", Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: hsl(0, 0%, 100%); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">1. text</span>';+ '<meta http-equiv="content-type" content="text/html; charset=utf-8"><ol><li>text</li></ol>';assert.equal(copy_and_paste.paste_handler_converter(input), "1. text");// Headinginput ='<meta http-equiv="content-type" content="text/html; charset=utf-8"><h1 style="box-sizing: border-box; font-size: 2em; margin-top: 0px !important; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; font-weight: 600; line-height: 1.25; padding-bottom: 0.3em; border-bottom: 1px solid hsl(216, 14%, 93%); color: hsl(210, 12%, 16%); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">Zulip overview</h1><p>normal text</p>';assert.equal(copy_and_paste.paste_handler_converter(input), "# Zulip overview\n\nnormal text");+ // Only heading (strip heading style)+ input =+ '<meta http-equiv="content-type" content="text/html; charset=utf-8"><h1 style="box-sizing: border-box; font-size: 2em; margin-top: 0px !important; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; font-weight: 600; line-height: 1.25; padding-bottom: 0.3em; border-bottom: 1px solid hsl(216, 14%, 93%); color: hsl(210, 12%, 16%); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">Zulip overview</h1>';+ assert.equal(copy_and_paste.paste_handler_converter(input), "Zulip overview");// Italic textinput =