fix build for now
This commit is contained in:
24
packages/html/src/example.js
Normal file
24
packages/html/src/example.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { generateHTML } from '@tiptap/html'
|
||||
|
||||
import Document from '@tiptap/extension-document'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Text from '@tiptap/extension-text'
|
||||
|
||||
// eslint-disable-next-line
|
||||
const html = generateHTML({
|
||||
type: 'document',
|
||||
content: [{
|
||||
type: 'paragraph',
|
||||
attrs: {
|
||||
align: 'left',
|
||||
},
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: 'Example Text',
|
||||
}],
|
||||
}],
|
||||
}, [
|
||||
new Document(),
|
||||
new Paragraph(),
|
||||
new Text(),
|
||||
])
|
||||
13
packages/html/src/getHTMLFromFragment.ts
Normal file
13
packages/html/src/getHTMLFromFragment.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Node, DOMSerializer, Schema } from 'prosemirror-model'
|
||||
// @ts-ignore
|
||||
import { createHTMLDocument } from 'hostic-dom'
|
||||
|
||||
export default function getHTMLFromFragment(doc: Node, schema: Schema): string {
|
||||
return DOMSerializer
|
||||
.fromSchema(schema)
|
||||
.serializeFragment(doc.content, {
|
||||
document: createHTMLDocument(),
|
||||
})
|
||||
// @ts-ignore
|
||||
.render()
|
||||
}
|
||||
10
packages/html/src/index.ts
Normal file
10
packages/html/src/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Extensions, getSchema } from '@tiptap/core'
|
||||
import { Node } from 'prosemirror-model'
|
||||
import getHTMLFromFragment from './getHTMLFromFragment'
|
||||
|
||||
export function generateHTML(doc: object, extensions: Extensions): string {
|
||||
const schema = getSchema(extensions)
|
||||
const contentNode = Node.fromJSON(schema, doc)
|
||||
|
||||
return getHTMLFromFragment(contentNode, schema)
|
||||
}
|
||||
Reference in New Issue
Block a user