2021-05-06 05:10:45 +08:00
|
|
|
/// <reference types="cypress" />
|
|
|
|
|
|
|
|
import Document from '@tiptap/extension-document'
|
|
|
|
import Paragraph from '@tiptap/extension-paragraph'
|
|
|
|
import Text from '@tiptap/extension-text'
|
2021-07-20 18:53:19 +08:00
|
|
|
import TextAlign from '@tiptap/extension-text-align'
|
2022-06-08 20:10:25 +08:00
|
|
|
import { generateJSON } from '@tiptap/html'
|
2021-05-06 05:10:45 +08:00
|
|
|
|
|
|
|
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',
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
}))
|
|
|
|
})
|
2021-07-20 18:53:19 +08:00
|
|
|
|
|
|
|
// issue: https://github.com/ueberdosis/tiptap/issues/1601
|
|
|
|
it('generate JSON with style attributes', () => {
|
|
|
|
const html = '<p style="text-align: center;">Example Text</p>'
|
|
|
|
|
|
|
|
const json = generateJSON(html, [
|
|
|
|
Document,
|
|
|
|
Paragraph,
|
|
|
|
Text,
|
2021-07-20 19:01:54 +08:00
|
|
|
TextAlign.configure({ types: ['paragraph'] }),
|
2021-07-20 18:53:19 +08:00
|
|
|
])
|
|
|
|
|
|
|
|
expect(JSON.stringify(json)).to.eq(JSON.stringify({
|
|
|
|
type: 'doc',
|
|
|
|
content: [{
|
|
|
|
type: 'paragraph',
|
|
|
|
attrs: {
|
2021-07-20 19:01:54 +08:00
|
|
|
textAlign: 'center',
|
2021-07-20 18:53:19 +08:00
|
|
|
},
|
|
|
|
content: [{
|
|
|
|
type: 'text',
|
|
|
|
text: 'Example Text',
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
}))
|
|
|
|
})
|
2021-05-06 05:10:45 +08:00
|
|
|
})
|