tiptap/packages/core/src/helpers/getHTMLFromFragment.ts
2021-12-03 00:03:39 +01:00

15 lines
465 B
TypeScript

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