feature: add generateJSON utility function to generate JSON from a HTML string

This commit is contained in:
Hans Pagel
2021-05-05 21:24:24 +02:00
parent 6f0fa6569d
commit 7feb19eb72
7 changed files with 86 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
/// <reference types="cypress" />
import { generateJSON } from '@tiptap/core'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
describe('generateJSON', () => {
it('generate HTML from JSON 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',
}],
}],
}))
})
})