import Document from '@tiptap/extension-document' import Paragraph from '@tiptap/extension-paragraph' import Text from '@tiptap/extension-text' import { TextStyle } from '@tiptap/extension-text-style' import Youtube from '@tiptap/extension-youtube' import { generateHTML } from './generateHTML.js' import { generateJSON } from './generateJSON.js' import StarterKit from '@tiptap/starter-kit' import { describe, expect, it } from 'vite-plus/test' 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).toBe('
Example Text
') }) it('can convert from & to html', async () => { const extensions = [Document, Paragraph, Text, Youtube] const html = `Tiptap now supports YouTube embeds! Awesome!
Tiptap now supports YouTube embeds! Awesome!
', ) }) it('can convert from & to HTML with a complex schema', async () => { const extensions = [StarterKit, TextStyle] const html = `this is a basic example of Tiptap. Sure, there are all kind of basic text styles you’d probably expect from a text editor. But wait until you see the lists:
Isn’t that great? And all of that is editable. But wait, there’s more. Let’s try a code block:
body {
display: none;
}
I know, I know, this is impressive. It’s only the tip of the iceberg though. Give it a try and click a little bit around. Don’t forget to check the other examples too.
Wow, that’s amazing. Good work, boy! 👏` const json = generateJSON(html, extensions) const expected = { type: 'doc', content: [ { type: 'heading', attrs: { level: 2, }, content: [ { type: 'text', text: 'Hi there,', }, ], }, { type: 'paragraph', content: [ { type: 'text', text: 'this is a ', }, { type: 'text', marks: [ { type: 'italic', }, ], text: 'basic', }, { type: 'text', text: ' example of ', }, { type: 'text', marks: [ { type: 'bold', }, ], text: 'Tiptap', }, { type: 'text', text: '. Sure, there are all kind of basic text styles you’d probably expect from a text editor. But wait until you see the lists:', }, ], }, { type: 'bulletList', content: [ { type: 'listItem', content: [ { type: 'paragraph', content: [ { type: 'text', text: 'That’s a bullet list with one …', }, ], }, ], }, { type: 'listItem', content: [ { type: 'paragraph', content: [ { type: 'text', text: '… or two list items.', }, ], }, ], }, ], }, { type: 'paragraph', content: [ { type: 'text', text: 'Isn’t that great? And all of that is editable. But wait, there’s more. Let’s try a code block:', }, ], }, { type: 'codeBlock', attrs: { language: 'css', }, content: [ { type: 'text', text: 'body {\n display: none;\n}', }, ], }, { type: 'paragraph', content: [ { type: 'text', text: 'I know, I know, this is impressive. It’s only the tip of the iceberg though. Give it a try and click a little bit around. Don’t forget to check the other examples too.', }, ], }, { type: 'blockquote', content: [ { type: 'paragraph', content: [ { type: 'text', text: 'Wow, that’s amazing. Good work, boy! 👏 ', }, { type: 'hardBreak', }, { type: 'text', text: '— Mom', }, ], }, ], }, ], } expect(json).toEqual(expected) expect(generateHTML(json, extensions)).toBe( `
— Mom
this is a basic example of Tiptap. Sure, there are all kind of basic text styles you’d probably expect from a text editor. But wait until you see the lists:
That’s a bullet list with one …
… or two list items.
Isn’t that great? And all of that is editable. But wait, there’s more. Let’s try a code block:
body {
display: none;
}I know, I know, this is impressive. It’s only the tip of the iceberg though. Give it a try and click a little bit around. Don’t forget to check the other examples too.
`, ) }) })Wow, that’s amazing. Good work, boy! 👏
— Mom