tiptap/packages/core/src/utils/generateHtml.ts
2020-09-04 12:02:37 +02:00

20 lines
613 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 div = temporaryDocument.createElement('div')
const fragment = DOMSerializer
.fromSchema(schema)
.serializeFragment(contentNode.content)
div.appendChild(fragment)
return div.innerHTML
}