https://github.com/afeiship/next-slate-serialize
Serializing slate nodes to html.
https://github.com/afeiship/next-slate-serialize
deserialize draftjs editor from-html from-text next nx serialize slate slatejs to-html to-text
Last synced: 27 days ago
JSON representation
Serializing slate nodes to html.
- Host: GitHub
- URL: https://github.com/afeiship/next-slate-serialize
- Owner: afeiship
- License: mit
- Created: 2021-01-24T07:53:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-29T13:50:52.000Z (over 5 years ago)
- Last Synced: 2025-10-22T05:19:04.384Z (7 months ago)
- Topics: deserialize, draftjs, editor, from-html, from-text, next, nx, serialize, slate, slatejs, to-html, to-text
- Language: JavaScript
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# next-slate-serialize
> Serializing/deserializing html/text for slate.
[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]
## installation
```bash
npm install -S @jswork/next-slate-serialize
```
## apis
| api | params | description |
| --- | ------------------ | ------------------------ |
| parse | inNodes, inOptions | Transform nodes to html. |
## usage
```js
import NxSlateSerialize from '@jswork/next-slate-serialize';
// apis
const nodes = [
{
children: [
{
type: 'paragraph',
children: [
{ text: 'An opening paragraph with a ' },
{
type: 'link',
url: 'https://example.com',
children: [{ text: 'link' }]
},
{ text: ' in it.' }
]
},
{
type: 'quote',
children: [{ text: 'A wise quote.' }]
},
{
type: 'paragraph',
children: [{ text: 'A closing paragraph!' }]
}
]
}
];
const options = {
process: (node, children) => {
if (!children) return node.text;
switch (node.type) {
case 'quote':
return `
${children}
`;
case 'paragraph':
return `${children}
`;
case 'link':
return `${children}`;
default:
return children;
}
},
joined: ''
};
const html = NxSlateSerialize.parse(nodes, options);
//
An opening paragraph with a link in it.
A wise quote.
A closing paragraph!
```
## resources
- https://docs.slatejs.org/concepts/09-serializing
## license
Code released under [the MIT license](https://github.com/afeiship/next-slate-serialize/blob/master/LICENSE.txt).
[version-image]: https://img.shields.io/npm/v/@jswork/next-slate-serialize
[version-url]: https://npmjs.org/package/@jswork/next-slate-serialize
[license-image]: https://img.shields.io/npm/l/@jswork/next-slate-serialize
[license-url]: https://github.com/afeiship/next-slate-serialize/blob/master/LICENSE.txt
[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/next-slate-serialize
[size-url]: https://github.com/afeiship/next-slate-serialize/blob/master/dist/next-slate-serialize.min.js
[download-image]: https://img.shields.io/npm/dm/@jswork/next-slate-serialize
[download-url]: https://www.npmjs.com/package/@jswork/next-slate-serialize