Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: pasting list item with single spaced paragraphs shouldn't break formatting

Abdullah Atta406cb663c930
diff --git a/packages/editor/src/extensions/clipboard/clipboard-dom-parser.ts b/packages/editor/src/extensions/clipboard/clipboard-dom-parser.ts
index 0c6ccbd4a..a7f41e5a1 100644
--- a/packages/editor/src/extensions/clipboard/clipboard-dom-parser.ts
+++ b/packages/editor/src/extensions/clipboard/clipboard-dom-parser.ts
@@ -161,12 +161,49 @@ function splitOn(bound: Element, cutElement: Element) {
}
}
+const inlineTags = new Set([
+ "A",
+ "ABBR",
+ "B",
+ "BDI",
+ "BDO",
+ // "BR",
+ "CITE",
+ "CODE",
+ "DATA",
+ "DFN",
+ "EM",
+ "I",
+ // "IMG",
+ // "INPUT",
+ "KBD",
+ "LABEL",
+ "MARK",
+ "Q",
+ "S",
+ "SAMP",
+ "SMALL",
+ "SPAN",
+ "STRONG",
+ "SUB",
+ "SUP",
+ "TEXTAREA",
+ "TIME",
+ "U",
+ "VAR",
+ "WBR"
+]);
+
function getSiblingTextNodes(element: ChildNode) {
const siblings = [];
let sibling: ChildNode | null = element;
while ((sibling = sibling.previousSibling)) {
- if (sibling.nodeType === Node.ELEMENT_NODE) break;
- else if (sibling.nodeType === Node.TEXT_NODE) siblings.push(sibling);
+ if (isElement(sibling) && !inlineTags.has(sibling.tagName)) break;
+ else siblings.push(sibling);
}
return siblings;
}
+
+function isElement(node: ChildNode): node is HTMLElement {
+ return node.nodeType === Node.ELEMENT_NODE;
+}
diff --git a/packages/editor/src/extensions/clipboard/tests/__snapshots__/clipboard-dom-parser.test.ts.snap b/packages/editor/src/extensions/clipboard/tests/__snapshots__/clipboard-dom-parser.test.ts.snap
index efee0d3d4..fe4582ea8 100644
--- a/packages/editor/src/extensions/clipboard/tests/__snapshots__/clipboard-dom-parser.test.ts.snap
+++ b/packages/editor/src/extensions/clipboard/tests/__snapshots__/clipboard-dom-parser.test.ts.snap
@@ -11,7 +11,7 @@ exports[`convert br tags to paragraphs 4`] = `"<p>line <span><em>1</em></span></
exports[`convert br tags to paragraphs 5`] = `"<p></p>"`;
exports[`convert br tags to paragraphs 6`] = `
-"<!--StartFragment--><p data-spacing=\\"single\\">A troll, they call me, but I have no wish
+"<p data-spacing=\\"single\\">A troll, they call me, but I have no wish<!--StartFragment-->
</p><p data-spacing=\\"single\\">
to be associated with those dolls</p><p data-spacing=\\"single\\">
</p><p data-spacing=\\"single\\">
@@ -75,6 +75,8 @@ exports[`convert br tags to paragraphs 12`] = `
</div>"
`;
+exports[`convert br tags to paragraphs 13`] = `"<ul xmlns=\\"http://www.w3.org/1999/xhtml\\" data-block-id=\\"A9jEKaAm\\" class=\\"checklist\\"><li class=\\"checklist--item\\"><p data-spacing=\\"single\\"><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a>hello <a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a></p><p data-spacing=\\"single\\"><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a></p><p data-spacing=\\"single\\"><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a></p><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a></li><li class=\\"checklist--item\\"><p data-spacing=\\"single\\"><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a></p><p data-spacing=\\"single\\"><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a></p><p data-spacing=\\"single\\"><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a></p><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a></li><li class=\\"checklist--item\\"><p data-spacing=\\"single\\"><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hellohello</a></p><p data-spacing=\\"single\\"><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello hello hello</a></p><p data-spacing=\\"single\\"><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a></p><a target=\\"_blank\\" rel=\\"noopener noreferrer nofollow\\" href=\\"https://google.com\\">hello</a></li><li class=\\"checklist--item\\">vsvdsavdsa</li><li class=\\"checklist--item\\">vadsvasdv</li></ul><p xmlns=\\"http://www.w3.org/1999/xhtml\\" data-block-id=\\"CuscJzDm\\" data-spacing=\\"double\\"></p>"`;
+
exports[`convert google docs checklist 1`] = `
"<div>
<!--StartFragment--><meta charset=\\"utf-8\\"><ul id=\\"docs-internal-guid-0d9a5db3-7fff-ab55-e7ca-b178e1031970\\" class=\\"checklist\\"><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-level=\\"1\\" class=\\"checklist--item\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>Adsjkfhasdf</span></p></li><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-level=\\"1\\" class=\\"checklist--item\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>Asdfsadf</span></p></li><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"true\\" aria-level=\\"1\\" class=\\"checklist--item checked\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>Asdfsda</span></p></li><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"true\\" aria-level=\\"1\\" class=\\"checklist--item checked\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>Fasd</span></p></li><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"true\\" aria-level=\\"1\\" class=\\"checklist--item checked\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>Fasd</span></p></li><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-level=\\"1\\" class=\\"checklist--item\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>F</span></p></li><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"true\\" aria-level=\\"1\\" class=\\"checklist--item checked\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>akcasb</span></p></li><ul class=\\"checklist\\"><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"true\\" aria-level=\\"2\\" class=\\"checklist--item checked\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>Asdf</span></p></li><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-level=\\"2\\" class=\\"checklist--item\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>Asdcasdc</span></p></li><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-level=\\"2\\" class=\\"checklist--item\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>sdac</span></p></li></ul><li dir=\\"ltr\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-level=\\"1\\" class=\\"checklist--item\\"><p dir=\\"ltr\\" role=\\"presentation\\"><span>Asdfsda</span></p></li></ul><!--EndFragment-->
diff --git a/packages/editor/src/extensions/clipboard/tests/clipboard-dom-parser.test.ts b/packages/editor/src/extensions/clipboard/tests/clipboard-dom-parser.test.ts
index d7af07d56..f03cbd0be 100644
--- a/packages/editor/src/extensions/clipboard/tests/clipboard-dom-parser.test.ts
+++ b/packages/editor/src/extensions/clipboard/tests/clipboard-dom-parser.test.ts
@@ -98,6 +98,9 @@ and yet, we somehow manage to get by.<br>
<!--StartFragment--><meta charset="utf-8"><h1><span >Write notes</span></h1><br><p dir="ltr" ><span >Welcome of </span><a><span >Notesnook</span></a><span >, an syncing.</span></p><br><p dir="ltr" ><span >Enjoy the read!</span></p><br><p dir="ltr" ><span ><span ><img></span></span></p><br><p dir="ltr" ><span >vision?</span></p><br><p dir="ltr" ><span >everyone means</span></p><!--EndFragment-->
</div>`
+ ],
+ [
+ `<ul xmlns="http://www.w3.org/1999/xhtml" data-block-id="A9jEKaAm" class="checklist"><li class="checklist--item"><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a>hello <a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a><br /><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a><br /><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a><br /><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a></li><li class="checklist--item"><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a><br /><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a><br /><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a><br /><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a></li><li class="checklist--item"><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hellohello</a><br /><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello hello hello</a><br /><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a><br /><a target="_blank" rel="noopener noreferrer nofollow" href="https://google.com">hello</a></li><li class="checklist--item">vsvdsavdsa</li><li class="checklist--item">vadsvasdv</li></ul><p xmlns="http://www.w3.org/1999/xhtml" data-block-id="CuscJzDm" data-spacing="double"></p>`
]
];