Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsist slate AST when transforming empty strings #129

Closed
rodikh opened this issue Feb 7, 2023 · 3 comments · Fixed by #130
Closed

Inconsist slate AST when transforming empty strings #129

rodikh opened this issue Feb 7, 2023 · 3 comments · Fixed by #130
Assignees

Comments

@rodikh
Copy link

rodikh commented Feb 7, 2023

I've recently updated remark-slate-transformer from v0.2.1 to v0.7.3 and that introduced a breaking change for me with the generated Slate AST.

Previously, parsing an empty string (or a string with only whitespaces) would generate an empty array as a result of processSync.

const processor = unified().use(markdown).use(remarkToSlate);
const value1 = processor.processSync('').result; // => []
const value2 = processor.processSync(' ').result; // => []
const value3 = processor.processSync('val').result; // => [{"type": "paragraph", "children": [{"text": "val"}]}]

After updating remark-slate-transformer I am receiving a slightly different response.

const processor = unified().use(markdown).use(remarkToSlate);
const value1 = processor.processSync('').result; // => [[{"text": ""}]]
const value2 = processor.processSync(' ').result; // => [[{"text": ""}]]
const value3 = processor.processSync('val').result; // => [{"type": "paragraph", "children": [{"text": "val"}]}]

These two results are not marked as paragraph nodes, which makes Slate freak out.

Is this the expected behavior? how do I make sure that remark-slate-transformer returns a paragraph node as root if nothing else is parsed?

@inokawa
Copy link
Owner

inokawa commented Feb 7, 2023

It is the behavior introduced in #42 .
The bug was caused by empty list, so it might be better to fix only list not all nodes.

@inokawa
Copy link
Owner

inokawa commented Feb 7, 2023

Published in 0.7.4.

@rodikh
Copy link
Author

rodikh commented Feb 7, 2023

Thanks for the quick fix @inokawa.
I can confirm that it works properly and slate is no longer confused :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants