mirror of https://github.com/zulip/zulip.git
copy_and_paste: Extract function `within_single_element` for reuse.
This is a prep commit for the next which will introduce a new function that also calls `within_single_element`.
This commit is contained in:
parent
ad9f7a4549
commit
c440b4575e
|
@ -314,14 +314,19 @@ function image_to_zulip_markdown(_content, node) {
|
||||||
return src ? "[" + title + "](" + src + ")" : node.getAttribute("alt") || "";
|
return src ? "[" + title + "](" + src + ")" : node.getAttribute("alt") || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function within_single_element(html_fragment) {
|
||||||
|
return (
|
||||||
|
html_fragment.childNodes.length === 1 &&
|
||||||
|
html_fragment.firstElementChild &&
|
||||||
|
html_fragment.firstElementChild.innerHTML
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function paste_handler_converter(paste_html) {
|
export function paste_handler_converter(paste_html) {
|
||||||
const copied_html_fragment = new DOMParser()
|
const copied_html_fragment = new DOMParser()
|
||||||
.parseFromString(paste_html, "text/html")
|
.parseFromString(paste_html, "text/html")
|
||||||
.querySelector("body");
|
.querySelector("body");
|
||||||
const copied_within_single_element =
|
const copied_within_single_element = within_single_element(copied_html_fragment);
|
||||||
copied_html_fragment.childNodes.length === 1 &&
|
|
||||||
copied_html_fragment.firstElementChild &&
|
|
||||||
copied_html_fragment.firstElementChild.innerHTML;
|
|
||||||
const outer_elements_to_retain = ["PRE", "UL", "OL", "A", "CODE"];
|
const outer_elements_to_retain = ["PRE", "UL", "OL", "A", "CODE"];
|
||||||
// If the entire selection copied is within a single HTML element (like an
|
// If the entire selection copied is within a single HTML element (like an
|
||||||
// `h1`), we don't want to retain its styling, except when it is needed to
|
// `h1`), we don't want to retain its styling, except when it is needed to
|
||||||
|
|
Loading…
Reference in New Issue