tiptap/packages/html/src/generateJSON.ts
Dominik 8c6751f0c6
add precommit hook for linting and automatic eslint fixes + update eslint packages (#2862)
* chore: add precommit hook for eslint fixes, fix linting issues
* chore: add eslint import sort plugin
2022-06-08 14:10:25 +02:00

13 lines
386 B
TypeScript

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