mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-25 12:39:03 +08:00
refactor generateHtml to allow directly passing a Schema
This commit is contained in:
parent
c36ddaf8fc
commit
95fca8aa61
@ -1,16 +1,23 @@
|
||||
import getSchema from './getSchema'
|
||||
import { Node as ProseMirrorNode, DOMSerializer } from 'prosemirror-model'
|
||||
import { Extensions } from '../types'
|
||||
import { Schema } from 'prosemirror-model'
|
||||
|
||||
export default function generateHtml(doc: object, extensions: Extensions): string {
|
||||
const schema = getSchema(extensions)
|
||||
export default function generateHtml(doc: object, schema: (Extensions | Schema)): string {
|
||||
let useSchema
|
||||
|
||||
let contentNode = ProseMirrorNode.fromJSON(schema, doc)
|
||||
let temporaryDocument = document.implementation.createHTMLDocument()
|
||||
if (Array.isArray(schema)) {
|
||||
useSchema = getSchema(schema as Extensions)
|
||||
} else {
|
||||
useSchema = schema as Schema
|
||||
}
|
||||
|
||||
const contentNode = ProseMirrorNode.fromJSON(useSchema, doc)
|
||||
const temporaryDocument = document.implementation.createHTMLDocument()
|
||||
const container = temporaryDocument.createElement('div')
|
||||
|
||||
const fragment = DOMSerializer
|
||||
.fromSchema(schema)
|
||||
.fromSchema(useSchema)
|
||||
.serializeFragment(contentNode.content)
|
||||
|
||||
container.appendChild(fragment)
|
||||
|
Loading…
Reference in New Issue
Block a user