tiptap/packages/core/src/helpers/getHTMLFromFragment.ts
2020-11-30 09:42:53 +01:00

14 lines
438 B
TypeScript

import { Node, DOMSerializer, Schema } from 'prosemirror-model'
export default function getHTMLFromFragment(doc: Node, schema: Schema): string {
const fragment = DOMSerializer
.fromSchema(schema)
.serializeFragment(doc.content)
const temporaryDocument = document.implementation.createHTMLDocument()
const container = temporaryDocument.createElement('div')
container.appendChild(fragment)
return container.innerHTML
}