add a generateJSON utility to the HTML package

This commit is contained in:
Hans Pagel
2021-05-05 23:10:45 +02:00
parent 90380f207d
commit a9c0bf5982
10 changed files with 95 additions and 42 deletions

View File

@@ -0,0 +1,29 @@
/// <reference types="cypress" />
import { generateHTML } from 'packages/html/src/index'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
describe('generateHTML', () => {
it('generate HTML from JSON without an editor instance', () => {
const json = {
type: 'doc',
content: [{
type: 'paragraph',
content: [{
type: 'text',
text: 'Example Text',
}],
}],
}
const html = generateHTML(json, [
Document,
Paragraph,
Text,
])
expect(html).to.eq('<p>Example Text</p>')
})
})

View File

@@ -0,0 +1,29 @@
/// <reference types="cypress" />
import { generateJSON } from 'packages/html/src/index'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
describe('generateJSON', () => {
it('generate JSON from HTML without an editor instance', () => {
const html = '<p>Example Text</p>'
const json = generateJSON(html, [
Document,
Paragraph,
Text,
])
expect(JSON.stringify(json)).to.eq(JSON.stringify({
type: 'doc',
content: [{
type: 'paragraph',
content: [{
type: 'text',
text: 'Example Text',
}],
}],
}))
})
})