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 getSchema from './getSchema'
|
||||||
import { Node as ProseMirrorNode, DOMSerializer } from 'prosemirror-model'
|
import { Node as ProseMirrorNode, DOMSerializer } from 'prosemirror-model'
|
||||||
import { Extensions } from '../types'
|
import { Extensions } from '../types'
|
||||||
|
import { Schema } from 'prosemirror-model'
|
||||||
|
|
||||||
export default function generateHtml(doc: object, extensions: Extensions): string {
|
export default function generateHtml(doc: object, schema: (Extensions | Schema)): string {
|
||||||
const schema = getSchema(extensions)
|
let useSchema
|
||||||
|
|
||||||
let contentNode = ProseMirrorNode.fromJSON(schema, doc)
|
if (Array.isArray(schema)) {
|
||||||
let temporaryDocument = document.implementation.createHTMLDocument()
|
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 container = temporaryDocument.createElement('div')
|
||||||
|
|
||||||
const fragment = DOMSerializer
|
const fragment = DOMSerializer
|
||||||
.fromSchema(schema)
|
.fromSchema(useSchema)
|
||||||
.serializeFragment(contentNode.content)
|
.serializeFragment(contentNode.content)
|
||||||
|
|
||||||
container.appendChild(fragment)
|
container.appendChild(fragment)
|
||||||
|
Loading…
Reference in New Issue
Block a user