@@ -110,9 +110,6 @@ export function createBlockSpec<
110110 ] ;
111111 } ,
112112
113- // TODO: Do we need renderHTML if we have a node view? Doesn't seem like it
114- // makes sense but throws an error if ctrl+A and ctrl+C if it's not
115- // implemented.
116113 renderHTML ( { HTMLAttributes } ) {
117114 // Create blockContent element
118115 const blockContent = document . createElement ( "div" ) ;
@@ -123,34 +120,45 @@ export function createBlockSpec<
123120 blockContent . setAttribute ( attribute , value ) ;
124121 }
125122
126- // Gets BlockNote editor instance
127- const editor = this . options . editor ! ;
128-
129- // Quite hacky but don't think there's a better way to do this. Since the
130- // contentDOM can be anywhere inside the DOM, we don't know which element
131- // it is. Calling render() will give us the contentDOM, but we need to
132- // provide a block as a parameter.
133- const getDummyBlock : ( ) => Block < BlockSchema > = ( ) =>
134- ( {
135- id : "" ,
136- type : "" ,
137- props : { } ,
138- content : [ ] ,
139- children : [ ] ,
140- } as Block < BlockSchema > ) ;
141-
142- // Render elements
143- const rendered = blockConfig . render ( getDummyBlock , editor ) ;
144- // Add elements to blockContent
145- blockContent . appendChild ( rendered . dom ) ;
123+ // TODO: This only works for content copied within BlockNote.
124+ // Creates contentDOM element to serialize inline content into.
125+ let contentDOM : HTMLDivElement | undefined ;
126+ if ( blockConfig . containsInlineContent ) {
127+ contentDOM = document . createElement ( "div" ) ;
128+ blockContent . appendChild ( contentDOM ) ;
129+ } else {
130+ contentDOM = undefined ;
131+ }
132+
133+ // Alternative approach to serializing the block.
134+ // // Gets BlockNote editor instance
135+ // const editor = this.options.editor!;
136+ //
137+ // // Quite hacky but don't think there's a better way to do this. Since the
138+ // // contentDOM can be anywhere inside the DOM, we don't know which element
139+ // // it is. Calling render() will give us the contentDOM, but we need to
140+ // // provide a block as a parameter.
141+ // const getDummyBlock: () => Block<BlockSchema> = () =>
142+ // ({
143+ // id: "",
144+ // type: "",
145+ // props: {},
146+ // content: [],
147+ // children: [],
148+ // } as Block<BlockSchema>);
149+ //
150+ // // Render elements
151+ // const rendered = blockConfig.render(getDummyBlock, editor);
152+ // // Add elements to blockContent
153+ // blockContent.appendChild(rendered.dom);
154+ //
155+ // const contentDOM = blockConfig.containsInlineContent
156+ // ? rendered.contentDOM
157+ // : undefined;
146158
147159 return {
148160 dom : blockContent ,
149- // I don't understand what's going on with the typing here
150- contentDOM :
151- "contentDOM" in rendered
152- ? ( rendered . contentDOM as HTMLDivElement )
153- : undefined ,
161+ contentDOM : contentDOM ,
154162 } ;
155163 } ,
156164
0 commit comments