import { describe, expect, it } from 'vitest'; import { deriveMarkdownFromEditorJSON } from './derive-markdown'; describe('deriveMarkdownFromEditorJSON (issue #39 export)', () => { it('converts a TipTap JSON document to Markdown', () => { // Shaped like `editor.getJSON()` output, including a mark, so the export // that a revoked user triggers reflects the local content faithfully. const json = { type: 'doc', content: [ { type: 'heading', attrs: { level: 2 }, content: [{ type: 'text', text: 'Title' }] }, { type: 'paragraph', content: [ { type: 'text', text: 'Some ' }, { type: 'text', marks: [{ type: 'bold' }], text: 'bold' }, { type: 'text', text: ' text.' }, ], }, ], }; const markdown = deriveMarkdownFromEditorJSON(json); expect(markdown).toContain('## Title'); expect(markdown).toContain('**bold**'); }); it('handles an empty document without throwing', () => { const json = { type: 'doc', content: [{ type: 'paragraph' }] }; expect(() => deriveMarkdownFromEditorJSON(json)).not.toThrow(); }); });