add a generateJSON utility to the HTML package
This commit is contained in:
13
packages/html/src/generateJSON.ts
Normal file
13
packages/html/src/generateJSON.ts
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user