feature: add generateJSON utility function to generate JSON from a HTML string

This commit is contained in:
Hans Pagel
2021-05-05 21:24:24 +02:00
parent 6f0fa6569d
commit 7feb19eb72
7 changed files with 86 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
import { DOMParser } from 'prosemirror-model'
import getSchema from './getSchema'
import elementFromString from '../utilities/elementFromString'
import { Extensions } from '../types'
export default function generateJSON(html: string, extensions: Extensions): Record<string, any> {
const schema = getSchema(extensions)
const dom = elementFromString(html)
return DOMParser.fromSchema(schema)
.parse(dom)
.toJSON()
}