add a generateJSON utility to the HTML package

This commit is contained in:
Hans Pagel
2021-05-05 23:10:45 +02:00
parent 90380f207d
commit a9c0bf5982
10 changed files with 95 additions and 42 deletions

View File

@@ -0,0 +1,13 @@
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()
}