mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-23 17:07:49 +08:00
20 lines
613 B
TypeScript
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
|
|
}
|