File tree Expand file tree Collapse file tree 5 files changed +138
-82
lines changed
packages/markdown/src/lib Expand file tree Collapse file tree 5 files changed +138
-82
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @udecode/plate-markdown ' : patch
3+ ---
4+
5+ Critical fix(` deserializeMd ` ): input ` > ` , ` >> ` , ` >>> ` should be deserialized to a single ` blockquote ` with empty text node.
Original file line number Diff line number Diff line change @@ -14,6 +14,46 @@ describe('deserializeMd', () => {
1414 plugins : [ MarkdownPlugin ] ,
1515 } ) ;
1616
17+ it ( 'should deserialize >>> to blockquote' , ( ) => {
18+ const input = '>>>a' ;
19+
20+ const output = (
21+ < fragment >
22+ < hblockquote >
23+ < htext > a</ htext >
24+ </ hblockquote >
25+ </ fragment >
26+ ) ;
27+
28+ expect ( deserializeMd ( editor , input ) ) . toEqual ( output ) ;
29+ } ) ;
30+
31+ it ( 'should deserialize empty blockquotes' , ( ) => {
32+ const input = '>' ;
33+
34+ const output = (
35+ < fragment >
36+ < hblockquote >
37+ < htext />
38+ </ hblockquote >
39+ </ fragment >
40+ ) ;
41+
42+ expect ( deserializeMd ( editor , input ) ) . toEqual ( output ) ;
43+ } ) ;
44+
45+ it ( 'should deserialize "> " as blockquotes' , ( ) => {
46+ const input = '> Blockquote content' ;
47+
48+ const output = (
49+ < fragment >
50+ < hblockquote > Blockquote content</ hblockquote >
51+ </ fragment >
52+ ) ;
53+
54+ expect ( deserializeMd ( editor , input ) ) . toEqual ( output ) ;
55+ } ) ;
56+
1757 it ( 'should deserialize paragraphs' , ( ) => {
1858 const input =
1959 'Paragraph 1 line 1\nParagraph 1 line 2\n\nParagraph 2 line 1' ;
@@ -411,7 +451,7 @@ describe('deserializeMdIndentList', () => {
411451 type : 'p' ,
412452 } ,
413453 {
414- children : [ ] ,
454+ children : [ { text : '' } ] ,
415455 indent : 1 ,
416456 listStyleType : 'disc' ,
417457 type : 'p' ,
Original file line number Diff line number Diff line change @@ -9,10 +9,19 @@ import { remarkTransformNode } from './remarkTransformNode';
99export const remarkDefaultElementRules : RemarkElementRules = {
1010 blockquote : {
1111 transform : ( node , options ) => {
12+ const children = node . children ?. length
13+ ? node . children . flatMap ( ( paragraph ) =>
14+ remarkTransformElementChildren ( paragraph , options )
15+ )
16+ : [ { text : '' } ] ;
17+
18+ // Flatten nested blockquotes (e.g. >>>)
19+ const flattenedChildren = children . flatMap ( ( child : any ) =>
20+ child . type ? child . children : [ child ]
21+ ) ;
22+
1223 return {
13- children : node . children ! . flatMap ( ( paragraph ) =>
14- remarkTransformElementChildren ( paragraph , options )
15- ) ,
24+ children : flattenedChildren ,
1625 type : options . editor . getType ( { key : 'blockquote' } ) ,
1726 } ;
1827 } ,
Original file line number Diff line number Diff line change @@ -10,7 +10,9 @@ export const remarkTransformElementChildren = (
1010) : TDescendant [ ] => {
1111 const { children } = node ;
1212
13- if ( ! children ) return [ ] ;
13+ if ( ! children || children . length === 0 ) {
14+ return [ { text : '' } ] ;
15+ }
1416
1517 return children . flatMap ( ( child ) => remarkTransformNode ( child , options ) ) ;
1618} ;
You can’t perform that action at this time.
0 commit comments