An open API service indexing awesome lists of open source software.

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.

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