11import {
22 BlockNoteSchema ,
3- addNodeAndExtensionsToSpec ,
3+ createBlockConfig ,
4+ createBlockSpec ,
45 createImageBlockConfig ,
56 createImageBlockSpec ,
67 createInlineContentSpec ,
78 createPageBreakBlockSpec ,
89 createStyleSpec ,
910 defaultProps ,
11+ parseDefaultProps ,
1012} from "@blocknote/core" ;
1113
1214// BLOCKS ----------------------------------------------------------------------
1315
1416// This is a modified version of the default image block that does not implement
1517// a `toExternalHTML` function. It's used to test if the custom serializer by
1618// default serializes custom blocks using their `render` function.
17- const SimpleImage = addNodeAndExtensionsToSpec (
18- {
19- type : "simpleImage" ,
20- propSchema : createImageBlockConfig ( { } ) . propSchema ,
21- content : "none" ,
22- } ,
19+ const SimpleImage = createBlockSpec (
20+ createBlockConfig (
21+ ( ) =>
22+ ( {
23+ type : "simpleImage" ,
24+ propSchema : createImageBlockConfig ( { } ) . propSchema ,
25+ content : "none" ,
26+ } ) as const ,
27+ ) ,
2328 {
2429 render ( block , editor ) {
2530 return createImageBlockSpec ( ) . implementation . render . call (
@@ -31,13 +36,27 @@ const SimpleImage = addNodeAndExtensionsToSpec(
3136 } ,
3237) ;
3338
34- const CustomParagraph = addNodeAndExtensionsToSpec (
35- {
36- type : "customParagraph" ,
37- propSchema : defaultProps ,
38- content : "inline" ,
39- } ,
39+ const CustomParagraph = createBlockSpec (
40+ createBlockConfig (
41+ ( ) =>
42+ ( {
43+ type : "customParagraph" ,
44+ propSchema : defaultProps ,
45+ content : "inline" ,
46+ } ) as const ,
47+ ) ,
4048 {
49+ parse : ( e ) => {
50+ if ( e . tagName !== "P" ) {
51+ return undefined ;
52+ }
53+
54+ if ( e . classList . contains ( "custom-paragraph" ) ) {
55+ return parseDefaultProps ( e ) ;
56+ }
57+
58+ return undefined ;
59+ } ,
4160 render : ( ) => {
4261 const paragraph = document . createElement ( "p" ) ;
4362 paragraph . className = "custom-paragraph" ;
@@ -50,7 +69,6 @@ const CustomParagraph = addNodeAndExtensionsToSpec(
5069 toExternalHTML : ( ) => {
5170 const paragraph = document . createElement ( "p" ) ;
5271 paragraph . className = "custom-paragraph" ;
53- paragraph . innerHTML = "Hello World" ;
5472
5573 return {
5674 dom : paragraph ,
@@ -59,12 +77,15 @@ const CustomParagraph = addNodeAndExtensionsToSpec(
5977 } ,
6078) ;
6179
62- const SimpleCustomParagraph = addNodeAndExtensionsToSpec (
63- {
64- type : "simpleCustomParagraph" ,
65- propSchema : defaultProps ,
66- content : "inline" ,
67- } ,
80+ const SimpleCustomParagraph = createBlockSpec (
81+ createBlockConfig (
82+ ( ) =>
83+ ( {
84+ type : "simpleCustomParagraph" ,
85+ propSchema : defaultProps ,
86+ content : "inline" ,
87+ } ) as const ,
88+ ) ,
6889 {
6990 render : ( ) => {
7091 const paragraph = document . createElement ( "p" ) ;
@@ -198,9 +219,9 @@ const FontSize = createStyleSpec(
198219export const testSchema = BlockNoteSchema . create ( ) . extend ( {
199220 blockSpecs : {
200221 pageBreak : createPageBreakBlockSpec ( ) ,
201- customParagraph : CustomParagraph ,
202- simpleCustomParagraph : SimpleCustomParagraph ,
203- simpleImage : SimpleImage ,
222+ customParagraph : CustomParagraph ( ) ,
223+ simpleCustomParagraph : SimpleCustomParagraph ( ) ,
224+ simpleImage : SimpleImage ( ) ,
204225 } ,
205226 inlineContentSpecs : {
206227 mention : Mention ,
0 commit comments