mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 16:43:57 +00:00
compose: Always retain ol tag when pasting content enclosed by it.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
// Heading
|
||||
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><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 text
|
||||
input =
|
||||
|
||||
Reference in New Issue
Block a user