@@ -27,4 +27,117 @@ describe('link test', () => {
2727
2828 expect ( formatChildren ( nodes ) ) . toEqual ( expectResult ) ;
2929 } ) ;
30+
31+ it ( 'paragraph > bold link' , ( ) => {
32+ const mdString = '[**example**](https://example.com)' ;
33+ const nodes = mdStringToSlate ( mdString ) ;
34+ const expectResult = [ {
35+ type : 'paragraph' ,
36+ children : [
37+ {
38+ text : '' ,
39+ } ,
40+ {
41+ type : 'link' ,
42+ url : 'https://example.com' ,
43+ title : null ,
44+ children : [
45+ { text : 'example' , bold : true }
46+ ]
47+ } ,
48+ {
49+ text : ''
50+ }
51+ ]
52+ } ] ;
53+
54+ expect ( formatChildren ( nodes ) ) . toEqual ( expectResult ) ;
55+ } ) ;
56+
57+ it ( 'paragraph > italic link' , ( ) => {
58+ const mdString = '[*example*](https://example.com)' ;
59+ const nodes = mdStringToSlate ( mdString ) ;
60+ const expectResult = [ {
61+ type : 'paragraph' ,
62+ children : [
63+ {
64+ text : '' ,
65+ } ,
66+ {
67+ type : 'link' ,
68+ url : 'https://example.com' ,
69+ title : null ,
70+ children : [
71+ { text : 'example' , italic : true }
72+ ]
73+ } ,
74+ {
75+ text : ''
76+ }
77+ ]
78+ } ] ;
79+
80+ expect ( formatChildren ( nodes ) ) . toEqual ( expectResult ) ;
81+ } ) ;
82+
83+ it ( 'paragraph > bold italic link' , ( ) => {
84+ const mdString = '[***example***](https://example.com)' ;
85+ const nodes = mdStringToSlate ( mdString ) ;
86+ const expectResult = [ {
87+ type : 'paragraph' ,
88+ children : [
89+ {
90+ text : '' ,
91+ } ,
92+ {
93+ type : 'link' ,
94+ url : 'https://example.com' ,
95+ title : null ,
96+ children : [
97+ { text : 'example' , italic : true , bold : true }
98+ ]
99+ } ,
100+ {
101+ text : ''
102+ }
103+ ]
104+ } ] ;
105+
106+ expect ( formatChildren ( nodes ) ) . toEqual ( expectResult ) ;
107+ } ) ;
108+
109+ it ( 'paragraph > link with nested styles' , ( ) => {
110+ const mdString = '[**bold and *italic***](https://example.com)' ;
111+ const nodes = mdStringToSlate ( mdString ) ;
112+ const link = formatChildren ( nodes ) [ 0 ] . children [ 1 ] ;
113+
114+ expect ( link . children ) . toEqual ( [
115+ { text : 'bold and ' , bold : true } ,
116+ { text : 'italic' , bold : true , italic : true } ,
117+ ] ) ;
118+ } ) ;
119+
120+ it ( 'paragraph > link with plain and bold text' , ( ) => {
121+ const mdString = '[a **bold** b](https://example.com)' ;
122+ const nodes = mdStringToSlate ( mdString ) ;
123+ const link = formatChildren ( nodes ) [ 0 ] . children [ 1 ] ;
124+
125+ expect ( link . children ) . toEqual ( [
126+ { text : 'a ' } ,
127+ { text : 'bold' , bold : true } ,
128+ { text : ' b' } ,
129+ ] ) ;
130+ } ) ;
131+
132+ it ( 'paragraph > link with multiple bold texts' , ( ) => {
133+ const mdString = '[**a** **b**](https://example.com)' ;
134+ const nodes = mdStringToSlate ( mdString ) ;
135+ const link = formatChildren ( nodes ) [ 0 ] . children [ 1 ] ;
136+
137+ expect ( link . children ) . toEqual ( [
138+ { text : 'a' , bold : true } ,
139+ { text : ' ' } ,
140+ { text : 'b' , bold : true } ,
141+ ] ) ;
142+ } ) ;
30143} ) ;
0 commit comments