mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-11 06:44:30 +08:00
20 lines
631 B
TypeScript
20 lines
631 B
TypeScript
import getSchema from './getSchema'
|
|
import { Node as ProseMirrorNode, DOMSerializer } from 'prosemirror-model'
|
|
import { Extensions } from '../types'
|
|
|
|
export default function generateHtml(doc: object, extensions: Extensions): string {
|
|
const schema = getSchema(extensions)
|
|
|
|
let contentNode = ProseMirrorNode.fromJSON(schema, doc)
|
|
let temporaryDocument = document.implementation.createHTMLDocument()
|
|
const container = temporaryDocument.createElement('div')
|
|
|
|
const fragment = DOMSerializer
|
|
.fromSchema(schema)
|
|
.serializeFragment(contentNode.content)
|
|
|
|
container.appendChild(fragment)
|
|
|
|
return container.innerHTML
|
|
}
|