tiptap/packages/core/src/utils/getHtmlFromFragment.ts

14 lines
438 B
TypeScript
Raw Normal View History

2020-09-24 06:29:05 +08:00
import { Node, DOMSerializer, Schema } from 'prosemirror-model'
2020-09-04 19:44:06 +08:00
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
}