You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/features/blocks/code-blocks.mdx
+41-33Lines changed: 41 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,25 +20,27 @@ Code blocks by default are a simple way to display code. But, BlockNote also sup
20
20
experience easy to use and reduce bundle size.
21
21
</Callout>
22
22
23
-
You can enable more advanced features by passing the `codeBlock` option when creatingthe editor.
23
+
You can enable more advanced features by extending the editor's default schema with a new `codeBlock`, which you can pass options into when creating. For more on extending the editor schema, see [Custom Schemas](/docs/features/custom-schemas).
24
24
25
25
```ts
26
26
const editor =newBlockNoteEditor({
27
-
codeBlock: {
28
-
indentLineWithTab: true,
29
-
defaultLanguage: "typescript",
30
-
supportedLanguages: {
31
-
typescript: {
32
-
name: "TypeScript",
33
-
aliases: ["ts"],
27
+
schema: BlockNoteSchema.create().extend({
28
+
codeBlock: createCodeBlockSpec({
29
+
indentLineWithTab: true,
30
+
defaultLanguage: "typescript",
31
+
supportedLanguages: {
32
+
typescript: {
33
+
name: "TypeScript",
34
+
aliases: ["ts"],
35
+
},
34
36
},
35
-
},
36
-
createHighlighter: () =>
37
-
createHighlighter({
38
-
themes: ["light-plus", "dark-plus"],
39
-
langs: [],
40
-
}),
41
-
},
37
+
createHighlighter: () =>
38
+
createHighlighter({
39
+
themes: ["light-plus", "dark-plus"],
40
+
langs: [],
41
+
}),
42
+
}),
43
+
}),
42
44
});
43
45
```
44
46
@@ -64,7 +66,7 @@ type CodeBlock = {
64
66
65
67
### Basic Setup
66
68
67
-
To enable code block syntax highlighting, you can use the `codeBlock` option in the `useCreateBlockNote` hook.
69
+
To enable code block syntax highlighting, you can extend the editor's default schema with a new `codeBlock`.
This will extend the default schema with a custom `codeBlock` that includes options from `@blocknote/code-block`, enabling syntax highlighting.
94
+
89
95
### Custom Themes & Languages
90
96
91
-
To configure a code block highlighting theme and language, you can use the `codeBlock` option in the `useCreateBlockNote` hook.
97
+
To configure a code block highlighting theme and language, you can again extend the editor's default schema with a new `codeBlock`.
92
98
93
99
This allows you to configure a [shiki](https://shiki.style) highlighter for the code blocks of your editor, allowing you to tailor the themes and languages you would like to use.
94
100
@@ -109,21 +115,23 @@ import { createHighlighter } from "./shiki.bundle.js";
The Inline Content Implementation defines how the inline content should be rendered to HTML.
108
105
109
106
```typescript
110
107
typeReactCustomInlineContentImplementation= {
108
+
meta?: {
109
+
draggable?:boolean;
110
+
};
111
111
render:React.FC<{
112
112
inlineContent:InlineContent;
113
113
contentRef?: (node:HTMLElement|null) =>void;
@@ -124,6 +124,8 @@ type ReactCustomInlineContentImplementation = {
124
124
125
125
-`draggable:` Specifies whether the inline content can be dragged within the editor. If set to `true`, the inline content will be draggable. Defaults to `false` if not specified. If this is true, you should add `data-drag-handle` to the DOM element that should function as the drag handle.
126
126
127
+
`meta?.draggable?:` Whether the inline content should be draggable.
128
+
127
129
<Callouttype="info">
128
130
_Note that since inline content is, by definition, inline, your component
To enable code block syntax highlighting, you can use the `codeBlock` option in the `useCreateBlockNote` hook. This is excluded by default to reduce bundle size.
3
+
To enable code block syntax highlighting, you can extend the editor's default schema with a new `codeBlock`, which you can pass options into when creating. By passing the default options from `@blocknote/code-block`, you can enable syntax highlighting. This is excluded by default to reduce bundle size.
To configure a code block highlighting theme and language, you can use the `codeBlock` option in the `useCreateBlockNote` hook.
3
+
To configure a code block highlighting theme and language, you can extend the editor's default schema with a new `codeBlock`, which you can pass options into when creating. You can then use a shiki highlighter to add custom syntax highlighting.
4
4
5
-
This allows you to configure a shiki highlighter for the code blocks of your editor, allowing you to tailor the themes and languages you would like to use.
6
-
7
-
To create a syntax highlighter, you can use the [shiki-codegen](https://shiki.style/packages/codegen) CLI for generating the code to create a syntax highlighter for your languages and themes.
8
-
9
-
For example to create a syntax highlighter using the optimized javascript engine, javascript, typescript, vue, with light and dark themes, you can run the following command:
First use the [shiki-codegen](https://shiki.style/packages/codegen) CLI to create a `shiki.bundle.ts` file. You can then pass this file into the `codeBlock` options when creating it.
0 commit comments