does it work from Slate to Markdown too?
horacioh opened this issue · 6 comments
I dunno if this is correct but, can I use this same plugin to convert Slate values to markdown?
thanks in advance!
You can't use it for slate -> markdown, but here is some code I'm using to serialize slate state -> markdown
https://gist.github.com/hanford/fa61e86a8559d2e50941f88be8b18b30
Going to go ahead and close this issue. I hope the above snippet works for you!
thanks!!
So import { serialize } from 'remark-slate';
is not meant to be used?
Because, it's working partially: It's not parsing newlines. But does with: value.map((v) => serialize(v)).join('\n')
And links are not parsed...
@TrySpace for links in my editor, I use something like this: https://gist.github.com/hanford/86aa09b3f1a2e937787791297f349545
remark-slate should handle serializing and deserializing though:
https://github.com/hanford/remark-slate/blob/master/test/deserialize/link.test.ts
https://github.com/hanford/remark-slate/blob/master/test/serialize/serialize-link.test.ts
@hanford thanks, but I don't see the difference, and don't really understand why both serialize AND deserialize want an object.
What I'm looking for is a function that accepts a string
of markdown and converts it to slate.
I mean, looking at these tests: https://github.com/hanford/remark-slate/blob/master/test/deserialize/transform.test.ts
deserialize({ type: 'heading', depth: 1, children: [{ value: 'hey' }] })
That basically looks like a slate object, so I'm not sure what the expected usecase for this is...
@TrySpace remark-slate works on mdast
which is a markdown AST, the structure the deserialize tests is using isn't a slate object, it's an mdast node provided by remark.
That basically looks like a slate object, so I'm not sure what the expected usecase for this is...
It's actually mocking what remark would passes to remark-slate, while it's similar to the slate state, the two aren't the same.
I believe the example script is roughly what you want:
import unified from 'unified';
import markdown from 'remark-parse';
import slate from 'remark-slate';
unified()
.use(markdown)
.use(slate)
.process("[my link](https://github.com)", (err, file) => {
if (err) throw err;
console.log({ res: file.result });
});
I've updated the readme to hopefully be more clear, and I've added another test using unfied and remark-parse to outline the basic usage.
Let me know if you have any more questions, a new issue would probably be best.