thompsonsj / slate-serializers

Serialize Slate JSON objects to HTML and vice versa. Define rules to modify the end result.
84 stars 12 forks source link

text in html that does is not inside a tag is lost in conversion #149

Closed tes735 closed 3 months ago

tes735 commented 3 months ago

It could be that I'm doing it wrong, but... here is the scenario:

I'm starting with html like the following:

<div>
<h1>whatever</h1>
text by itself
<span>more stuff</span>
</div>

Then I run htmlToSlate on it before adding it to the data for the slate editor. When I convert this htmlToSlate, the "text by itself" is lost. I can see when logging that it's not part of the "elements" after conversion unless I wrap that line in a div or something. Is there a trick to get this to work, or is it a bug? Thanks!

P. S. This is for a project where there are many instances of this so I don't have control over the data to fix it there.

tes735 commented 3 months ago

I think I, at least, found WHERE the issue might be, and it doesn't appear to be related to your code. The Slate docs have the following snippit. Note my comment. Closing.

export const resetNodes = ( editor: Editor, options: { nodes?: Node | Node[]; at?: Location; } = {} ): void => { const children = [...editor.children]; children.forEach(node => editor.apply({ type: 'remove_node', path: [0], node }));

if (options.nodes) { const nodes = Node.isNode(options.nodes) ? [options.nodes] : options.nodes; /**