tiptap/packages/html/getHtmlFromFragment.ts
Philipp Kühn 986946a950 refactoring
2020-09-10 09:36:52 +02:00

16 lines
503 B
TypeScript

import { Node, DOMSerializer } from 'prosemirror-model'
import { Schema } from 'prosemirror-model'
import { JSDOM } from 'jsdom'
export default function getHtmlFromFragment(doc: Node, schema: Schema): string {
const fragment = DOMSerializer
.fromSchema(schema)
.serializeFragment(doc.content)
const temporaryDocument = new JSDOM(`<!DOCTYPE html>`).window.document
const container = temporaryDocument.createElement('div')
container.appendChild(fragment)
return container.innerHTML
}