tommoor / slate-md-serializer

A Markdown serializer for the Slate editor framework
MIT License
64 stars 36 forks source link

Deserialized list item text wrapped in an extra paragraph node #24

Closed KrisBraun closed 5 years ago

KrisBraun commented 5 years ago

Before serializing, the node hierarchy for list items is

block:bulleted-list > block:list-item > text

After deserializing, it is

block:bulleted-list > block:list-item > block:paragraph > text

This causes issues with the common handling of pressing enter on a list item, since after deserialization, it creates a new paragraph rather than a new list item.

KrisBraun commented 5 years ago

I've found and tested a fix -- will put up a PR.

KrisBraun commented 5 years ago

Running and fixing up tests, I see the addition of the paragraph node may be an intentional generalization to handle nested lists. Can a maintainer confirm it's intentional that an extra paragraph node is always added? I may just need to handle that in my code even though there's no way to create those nodes directly in my case since I don't support entering nested lists.

tommoor commented 5 years ago

Hi @KrisBraun – I'm pretty sure this is intentional for the reason you stated. Perhaps you can enforce the paragraph using the Slate schema?

KrisBraun commented 5 years ago

Thanks, @tommoor. I tried the schema approach but couldn't figure out how to get it to unwrap the paragraph node. Handled it by checking in the key handlers to check if either the current node was a list-item, or its parent, and then split or unwrap appropriately (i.e. change.splitBlock(2) if in a paragraph inside a list item).

tl;dr I've got things working well now.