add a new getHtmlFromFragment method that is used in the editor and in the stand-alone generateHtml helper

This commit is contained in:
Hans Pagel
2020-09-04 13:06:54 +02:00
parent 95fca8aa61
commit 8cee629e19
4 changed files with 23 additions and 29 deletions

View File

@@ -0,0 +1,14 @@
import { Node as ProseMirrorNode, DOMSerializer } from 'prosemirror-model'
import { Schema } from 'prosemirror-model'
export default function getHtmlFromFragment(doc: ProseMirrorNode, 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
}