tiptap/packages/html/getHtmlFromFragment.ts

14 lines
372 B
TypeScript
Raw Normal View History

2020-09-24 06:29:05 +08:00
import { Node, DOMSerializer, Schema } from 'prosemirror-model'
2020-10-29 00:12:25 +08:00
// @ts-ignore
import { createHTMLDocument } from 'hostic-dom'
2020-09-04 19:44:27 +08:00
export default function getHtmlFromFragment(doc: Node, schema: Schema): string {
2020-10-29 00:12:25 +08:00
return DOMSerializer
2020-09-04 19:44:27 +08:00
.fromSchema(schema)
2020-10-29 00:12:25 +08:00
.serializeFragment(doc.content, {
document: createHTMLDocument(),
})
// @ts-ignore
.render()
2020-09-04 19:44:27 +08:00
}