@@ -44,23 +44,24 @@ import "@blocknote/core/style.css";
44
44
45
45
export default function App() {
46
46
// Stores the editor's contents as Markdown.
47
- const [markdown, setMarkdown] = useState <string | null >( null );
47
+ const [markdown, setMarkdown] = useState <string >( " " );
48
48
49
49
// Creates a new editor instance.
50
- const editor = useBlockNote ({
50
+ const editor: BlockNoteEditor | null = useBlockNote ({
51
51
// Listens for when the editor's contents change.
52
52
onEditorContentChange : (editor : BlockNoteEditor ) => {
53
53
// Converts the editor's contents from Block objects to Markdown and
54
54
// saves them.
55
55
const saveBlocksAsMarkdown = async () => {
56
- const markdown = await editor .blocksToMarkdown (editor .topLevelBlocks );
56
+ const markdown: string =
57
+ await editor .blocksToMarkdown (editor .topLevelBlocks );
57
58
setMarkdown (markdown );
58
59
};
59
60
saveBlocksAsMarkdown ();
60
61
}
61
62
});
62
63
63
- // Renders a BlockNote editor, and its contents as Markdown below.
64
+ // Renders the editor instance , and its contents as Markdown below.
64
65
return (
65
66
<div >
66
67
< BlockNoteView editor = {editor } / >
@@ -98,11 +99,14 @@ Tries to create `Block` and `InlineNode` objects based on Markdown syntax, thoug
98
99
99
100
``` typescript /App.tsx
100
101
import { useEffect , useState } from " react" ;
101
- import { BlockNoteEditor } from " @blocknote/core" ;
102
+ import { BlockNoteEditor , Block } from " @blocknote/core" ;
102
103
import { BlockNoteView , useBlockNote } from " @blocknote/react" ;
103
104
import " @blocknote/core/style.css" ;
104
105
105
106
export default function App() {
107
+ // Stores the current Markdown content.
108
+ const [markdown, setMarkdown] = useState <string >(" " );
109
+
106
110
// Creates a new editor instance.
107
111
const editor: BlockNoteEditor | null = useBlockNote ({
108
112
// Makes the editor non-editable.
@@ -111,23 +115,20 @@ export default function App() {
111
115
},
112
116
})
113
117
114
- // Stores the current Markdown content.
115
- const [markdown, setMarkdown] = useState <string >(" " );
116
-
117
118
useEffect (() => {
118
119
if (editor ) {
119
120
// Whenever the current Markdown content changes, converts it to an array
120
121
// of Block objects and replaces the editor's content with them.
121
122
const getBlocks = async () => {
122
- const blocks = await editor .markdownToBlocks (markdown );
123
+ const blocks: Block [] = await editor .markdownToBlocks (markdown );
123
124
editor .replaceBlocks (editor .topLevelBlocks , blocks );
124
125
};
125
126
getBlocks ();
126
127
}
127
128
}, [editor , markdown ]);
128
129
129
- // Renders a text area for you to write/paste Markdown in and a BlockNote
130
- // editor below, which displays the current Markdown as blocks.
130
+ // Renders a text area for you to write/paste Markdown in, and the editor
131
+ // instance below, which displays the current Markdown as blocks.
131
132
return (
132
133
<div >
133
134
< textarea
@@ -179,23 +180,23 @@ import "@blocknote/core/style.css";
179
180
180
181
export default function App() {
181
182
// Stores the editor's contents as HTML.
182
- const [html, setHTML] = useState <string | null >( null );
183
+ const [html, setHTML] = useState <string >( " " );
183
184
184
185
// Creates a new editor instance.
185
- const editor = useBlockNote ({
186
+ const editor: BlockNoteEditor | null = useBlockNote ({
186
187
// Listens for when the editor's contents change.
187
188
onEditorContentChange : (editor : BlockNoteEditor ) => {
188
189
// Converts the editor's contents from Block objects to HTML and saves
189
190
// them.
190
191
const saveBlocksAsHTML = async () => {
191
- const html = await editor .blocksToHTML (editor .topLevelBlocks );
192
+ const html: string = await editor .blocksToHTML (editor .topLevelBlocks );
192
193
setHTML (html );
193
194
};
194
195
saveBlocksAsHTML ();
195
196
}
196
197
});
197
198
198
- // Renders a BlockNote editor, and its contents as HTML below.
199
+ // Renders the editor instance , and its contents as HTML below.
199
200
return (
200
201
<div >
201
202
< BlockNoteView editor = {editor } / >
@@ -233,11 +234,14 @@ Tries to create `Block` objects out of any HTML block-level elements, and `Inlin
233
234
234
235
``` typescript /App.tsx
235
236
import { useEffect , useState } from " react" ;
236
- import { BlockNoteEditor } from " @blocknote/core" ;
237
+ import { BlockNoteEditor , Block } from " @blocknote/core" ;
237
238
import { BlockNoteView , useBlockNote } from " @blocknote/react" ;
238
239
import " @blocknote/core/style.css" ;
239
240
240
241
export default function App() {
242
+ // Stores the current HTML content.
243
+ const [html, setHTML] = useState <string >(" " );
244
+
241
245
// Creates a new editor instance.
242
246
const editor: BlockNoteEditor | null = useBlockNote ({
243
247
// Makes the editor non-editable.
@@ -246,22 +250,19 @@ export default function App() {
246
250
},
247
251
})
248
252
249
- // Stores the current HTML content.
250
- const [html, setHTML] = useState <string >(" " );
251
-
252
253
useEffect (() => {
253
254
if (editor ) {
254
255
// Whenever the current HTML content changes, converts it to an array of
255
256
// Block objects and replaces the editor's content with them.
256
257
const getBlocks = async () => {
257
- const blocks = await editor .HTMLToBlocks (html );
258
+ const blocks: Block [] = await editor .HTMLToBlocks (html );
258
259
editor .replaceBlocks (editor .topLevelBlocks , blocks );
259
260
};
260
261
getBlocks ();
261
262
}
262
263
}, [editor , html ]);
263
264
264
- // Renders a text area for you to write/paste HTML in and a BlockNote editor
265
+ // Renders a text area for you to write/paste HTML in, and the editor instance
265
266
// below, which displays the current HTML as blocks.
266
267
return (
267
268
<div >
0 commit comments