HTML to Slate AST converter for the GraphCMS's RichTextAST format.
This package needs to have the packages slate
and slate-hyperscript
installed, and jsdom
as well if you need to run the converter in nodejs.
# for node or isomorphic usage, jsdom is required
npm install jsdom
# required peer-dependancies
npm install [email protected] [email protected]
npm install @graphcms/html-to-slate-ast
☝️ htmlToSlateAst
returns a Promise
import { htmlToSlateAST } from '@graphcms/html-to-slate-ast';
const htmlString = '<div><p>test</p></div>'; // or import form a filr or database
const ast = await htmlToSlateAST(htmlString);
The output of this converstion is compatible with our RichTextAST
GraphQL type and can be used to import content in your Rich Text fields.
Example mutation:
mutation newArticle($title: String!, $content: RichTextAST) {
createArticle(data: { title: $title, content: $content }) {
id
title
content {
html
raw
}
}
}
See the docs about the Rich Text field type and Content Api mutations
Licensed under the MIT License.
Made with 💜 by GraphCMS 👋 join our community!