@@ -2,6 +2,20 @@ import React from 'react'
22import { describe , expect , it } from 'vitest'
33import { MDXEditor , MDXEditorMethods } from '../'
44import { render } from '@testing-library/react'
5+ import { $getRoot , createEditor , ParagraphNode , TextNode } from 'lexical'
6+ import { QuoteNode } from '@lexical/rich-text'
7+ import { importMarkdownToLexical } from '../importMarkdownToLexical'
8+ import { exportMarkdownFromLexical } from '../exportMarkdownFromLexical'
9+ import { MdastRootVisitor } from '../plugins/core/MdastRootVisitor'
10+ import { MdastParagraphVisitor } from '../plugins/core/MdastParagraphVisitor'
11+ import { MdastTextVisitor } from '../plugins/core/MdastTextVisitor'
12+ import { MdastBreakVisitor } from '../plugins/core/MdastBreakVisitor'
13+ import { LexicalRootVisitor } from '../plugins/core/LexicalRootVisitor'
14+ import { LexicalParagraphVisitor } from '../plugins/core/LexicalParagraphVisitor'
15+ import { LexicalTextVisitor } from '../plugins/core/LexicalTextVisitor'
16+ import { LexicalLinebreakVisitor } from '../plugins/core/LexicalLinebreakVisitor'
17+ import { MdastBlockQuoteVisitor } from '../plugins/quote/MdastBlockQuoteVisitor'
18+ import { LexicalQuoteVisitor } from '../plugins/quote/LexicalQuoteVisitor'
519
620// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
721; ( globalThis as any ) . IS_REACT_ACT_ENVIRONMENT = true
@@ -34,6 +48,48 @@ describe('markdown import export', () => {
3448 testIdenticalMarkdown ( `Hello\n\nWorld` )
3549 } )
3650
51+ it ( 'preserves empty lines inside blockquotes across lexical markdown round-trips' , ( ) => {
52+ const editor = createEditor ( {
53+ namespace : 'test-editor' ,
54+ nodes : [ ParagraphNode , TextNode , QuoteNode ] ,
55+ onError ( error ) {
56+ throw error
57+ }
58+ } )
59+
60+ let exportedMarkdown = ''
61+
62+ editor . update ( ( ) => {
63+ importMarkdownToLexical ( {
64+ root : $getRoot ( ) ,
65+ markdown : `> one
66+ > two
67+ >
68+ > three` ,
69+ visitors : [ MdastRootVisitor , MdastParagraphVisitor , MdastTextVisitor , MdastBreakVisitor , MdastBlockQuoteVisitor ] as any ,
70+ syntaxExtensions : [ ] ,
71+ mdastExtensions : [ ] ,
72+ jsxComponentDescriptors : [ ] ,
73+ directiveDescriptors : [ ] ,
74+ codeBlockEditorDescriptors : [ ]
75+ } )
76+
77+ exportedMarkdown = exportMarkdownFromLexical ( {
78+ root : $getRoot ( ) ,
79+ visitors : [ LexicalRootVisitor , LexicalParagraphVisitor , LexicalTextVisitor , LexicalLinebreakVisitor , LexicalQuoteVisitor ] as any ,
80+ toMarkdownExtensions : [ ] ,
81+ toMarkdownOptions : { } ,
82+ jsxComponentDescriptors : [ ] ,
83+ jsxIsAvailable : false
84+ } ) . trim ( )
85+ } )
86+
87+ expect ( exportedMarkdown ) . toEqual ( `> one
88+ > two
89+ >
90+ > three` )
91+ } )
92+
3793 it ( 'works with italics' , ( ) => {
3894 testIdenticalMarkdown ( `*Hello* World` )
3995 } )
0 commit comments