init @tiptap/html package
This commit is contained in:
16
packages/html/getHtmlFromFragment.ts
Normal file
16
packages/html/getHtmlFromFragment.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Node, DOMSerializer } from 'prosemirror-model'
|
||||
import { Schema } from 'prosemirror-model'
|
||||
const jsdom = require('jsdom')
|
||||
const { JSDOM } = 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
|
||||
}
|
||||
Reference in New Issue
Block a user