2021-09-29 03:34:57 +08:00
|
|
|
import { DOMSerializer, Schema, Fragment } from 'prosemirror-model'
|
2020-09-04 19:06:54 +08:00
|
|
|
|
2021-09-29 03:34:57 +08:00
|
|
|
export default function getHTMLFromFragment(fragment: Fragment, schema: Schema): string {
|
|
|
|
const documentFragment = DOMSerializer
|
2020-09-04 19:06:54 +08:00
|
|
|
.fromSchema(schema)
|
2021-09-29 03:34:57 +08:00
|
|
|
.serializeFragment(fragment)
|
2020-09-04 19:06:54 +08:00
|
|
|
|
|
|
|
const temporaryDocument = document.implementation.createHTMLDocument()
|
|
|
|
const container = temporaryDocument.createElement('div')
|
2021-12-03 07:03:39 +08:00
|
|
|
|
2021-09-29 03:34:57 +08:00
|
|
|
container.appendChild(documentFragment)
|
2020-09-04 19:06:54 +08:00
|
|
|
|
|
|
|
return container.innerHTML
|
|
|
|
}
|