mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-21 15:28:09 +08:00
16 lines
469 B
TypeScript
16 lines
469 B
TypeScript
import { Node, DOMSerializer, 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
|
|
}
|