Open goldblatt opened 1 year ago
Thanks for reporting this. That looks like semantically valid HTML, so we should be able to handle it. Will look into this one.
FWIW i did a little hacking with _htmlConversions and edited https://github.com/facebook/lexical/blob/main/packages/lexical-list/src/utils.ts#L201
to be something like
function normalizeChildren(nodes: Array<LexicalNode>): Array<ListItemNode> {
const normalizedListItems: Array<ListItemNode> = [];
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
if ($isListItemNode(node)) {
const children = node.getChildren();
if (children.length > 0) {
normalizedListItems.push(...normalizeChildren(children));
}
} else {
normalizedListItems.push(wrapInListItem(node));
}
}
return normalizedListItems;
}
I think this works for my use cases, but there was a lot of surfaces to test for copy paste. It also seems weird to ignore the list item nodes but i think they get processed separately? idk in general i felt like I was missing some information so hopefully you'll have an easier time on your side!
Awesome, very helpful!
By the way, there's an entire system in place for overriding copy and paste behavior so you don't have to patch internal properties:
https://lexical.dev/docs/concepts/serialization#html---lexical
ooo an example with copy/paste might be helpful there. I had seen that page, but wasn't totally sure how to combine the concepts since I wanted to mostly keep the copy/paste functionality y'all had (since it's I think better than what I could write on my own 😄)
EDIT: I see the instructions, classic friday brain-- LexicalNode.importDOM()
also my solution does not work in all cases sadly!
When I paste the following text from notion
with the metadata
The text in the editor ends up garbled like
Lexical version: 0.9.1
Steps To Reproduce
Link to code example: This happens in the playground
The current behavior
Nodes are out of order
The expected behavior
Nodes in order or more similar to the original text