tiptap/packages/html/src/generateJSON.ts
2021-05-05 23:10:45 +02:00

14 lines
391 B
TypeScript

import { DOMParser } from 'prosemirror-model'
import { getSchema, Extensions } from '@tiptap/core'
// @ts-ignore
import { parseHTML } from 'hostic-dom'
export default function generateJSON(html: string, extensions: Extensions): Record<string, any> {
const schema = getSchema(extensions)
const dom = parseHTML(html)
return DOMParser.fromSchema(schema)
.parse(dom)
.toJSON()
}