11import { H1Plugin } from '@platejs/basic-nodes/react' ;
2+ import { BoldPlugin } from '@platejs/basic-nodes/react' ;
23import { createPlateEditor , ParagraphPlugin } from 'platejs/react' ;
34
5+ import { deserializeMd } from '../deserializer' ;
46import { MarkdownPlugin } from '../MarkdownPlugin' ;
57import { serializeMd } from '../serializer' ;
68
79describe ( 'defaultRules' , ( ) => {
8- it ( 'should serialize default keys' , ( ) => {
10+ it ( 'should serialize custom keys' , ( ) => {
911 const nodes = [
1012 {
1113 children : [ { text : 'Heading 1' } ] ,
12- type : 'h1' ,
14+ type : 'custom- h1' ,
1315 } ,
1416 {
1517 children : [ { text : 'Paragraph' } ] ,
16- type : 'p' ,
18+ type : 'custom- p' ,
1719 } ,
1820 ] ;
1921
2022 const editor = createPlateEditor ( {
21- plugins : [ MarkdownPlugin , H1Plugin , ParagraphPlugin ] ,
23+ plugins : [
24+ MarkdownPlugin ,
25+ H1Plugin . configure ( {
26+ node : { type : 'custom-h1' } ,
27+ } ) ,
28+ ParagraphPlugin . configure ( {
29+ node : { type : 'custom-p' } ,
30+ } ) ,
31+ ] ,
2232 } ) ;
2333
2434 const result = serializeMd ( editor , { value : nodes } ) ;
2535 expect ( result ) . toMatchSnapshot ( ) ;
2636 } ) ;
2737
28- it ( 'should serialize custom keys' , ( ) => {
38+ it ( 'should serialize custom mark' , ( ) => {
39+ const nodes = [
40+ {
41+ children : [
42+ { text : 'Paragraph' } ,
43+ { 'custom-bold' : true , text : 'text' } ,
44+ ] ,
45+ type : 'custom-p' ,
46+ } ,
47+ ] ;
48+
49+ const editor = createPlateEditor ( {
50+ plugins : [
51+ MarkdownPlugin ,
52+ H1Plugin . configure ( {
53+ node : { type : 'custom-h1' } ,
54+ } ) ,
55+ ParagraphPlugin . configure ( {
56+ node : { type : 'custom-p' } ,
57+ } ) ,
58+ BoldPlugin . configure ( {
59+ node : { type : 'custom-bold' } ,
60+ } ) ,
61+ ] ,
62+ } ) ;
63+
64+ const result = serializeMd ( editor , { value : nodes } ) ;
65+ expect ( result ) . toMatchSnapshot ( ) ;
66+ } ) ;
67+
68+ it ( 'should deserialize custom keys' , ( ) => {
2969 const nodes = [
3070 {
3171 children : [ { text : 'Heading 1' } ] ,
@@ -40,12 +80,50 @@ describe('defaultRules', () => {
4080 const editor = createPlateEditor ( {
4181 plugins : [
4282 MarkdownPlugin ,
43- H1Plugin . configure ( { key : 'custom-h1' as any } ) ,
44- ParagraphPlugin . configure ( { key : 'custom-p' as any } ) ,
83+ H1Plugin . configure ( {
84+ node : { type : 'custom-h1' } ,
85+ } ) ,
86+ ParagraphPlugin . configure ( {
87+ node : { type : 'custom-p' } ,
88+ } ) ,
4589 ] ,
4690 } ) ;
4791
48- const result = serializeMd ( editor , { value : nodes } ) ;
49- expect ( result ) . toMatchSnapshot ( ) ;
92+ const result = deserializeMd ( editor , '# Heading 1\nParagraph' ) ;
93+ expect ( result ) . toEqual ( nodes ) ;
94+ } ) ;
95+
96+ it ( 'should deserialize custom mark' , ( ) => {
97+ const nodes = [
98+ {
99+ children : [ { text : 'Heading 1' } ] ,
100+ type : 'custom-h1' ,
101+ } ,
102+ {
103+ children : [
104+ { text : 'Paragraph' } ,
105+ { 'custom-bold' : true , text : 'text' } ,
106+ ] ,
107+ type : 'custom-p' ,
108+ } ,
109+ ] ;
110+
111+ const editor = createPlateEditor ( {
112+ plugins : [
113+ MarkdownPlugin ,
114+ H1Plugin . configure ( {
115+ node : { type : 'custom-h1' } ,
116+ } ) ,
117+ ParagraphPlugin . configure ( {
118+ node : { type : 'custom-p' } ,
119+ } ) ,
120+ BoldPlugin . configure ( {
121+ node : { type : 'custom-bold' } ,
122+ } ) ,
123+ ] ,
124+ } ) ;
125+
126+ const result = deserializeMd ( editor , '# Heading 1\nParagraph**text**' ) ;
127+ expect ( result ) . toEqual ( nodes ) ;
50128 } ) ;
51129} ) ;
0 commit comments