Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ In addition to the default inline content types that BlockNote offers, you can a

## Creating a Custom Inline Content Type

Use the `createReactInlineContentSpec` function to create a custom inline content type. This function takes two arguments:
Use the `createReactInlineContentSpec` function to create a custom inline content type. This function takes three arguments:

```typescript
function createReactInlineContentSpec(
blockConfig: CustomInlineContentConfig,
blockImplementation: ReactInlineContentImplementation,
extensions?: (Extension | ExtensionFactoryInstance)[],
): InlineContentSpec;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
```

Expand Down Expand Up @@ -157,6 +158,12 @@ type ReactCustomInlineContentImplementation = {
should also return an HTML inline element._
</Callout>

### Inline Content Extensions

While the example on this page doesn't use it, `createReactInlineContentSpec` takes a third, optional argument `extensions`. This is for adding editor `extensions` that are specific to the inline content, which you can find out more about [here](/docs/features/extensions).

Inline content extensions are typically things like keyboard shortcuts, or input rules that turn typed text into the inline content.

## Adding Custom Inline Content to the Editor

Finally, create a BlockNoteSchema using the definition of your custom inline content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ it("registers extensions and plugins from editor options, nested extensions, and
const inlineSpec = createInlineContentSpec(
{ type: "customInline", propSchema: {}, content: "styled" },
{ render },
[inline.extension()],
);
const styleSpec = createStyleSpec(
{ type: "customStyle", propSchema: "boolean" },
Expand All @@ -275,7 +276,6 @@ it("registers extensions and plugins from editor options, nested extensions, and
inlineContentSpecs: {
customInline: {
...inlineSpec,
extensions: [inline.extension()],
implementation: {
...inlineSpec.implementation,
node: inlineSpec.implementation.node.extend({
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/schema/inlineContent/createSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {
import { inlineContentToNodes } from "../../api/nodeConversions/blockToNode.js";
import { nodeToCustomInlineContent } from "../../api/nodeConversions/nodeToBlock.js";
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
import type {
Extension,
ExtensionFactoryInstance,
} from "../../editor/BlockNoteExtension.js";
import { ignoreDarkReaderMutations } from "../nodeViewMutations.js";
import { propsToAttributes } from "../blocks/internal.js";
import { nonFormattingMarks } from "../markGroups.js";
Expand Down Expand Up @@ -259,6 +263,7 @@ export function createInlineContentSpec<
>(
inlineContentConfig: T,
inlineContentImplementation: CustomInlineContentImplementation<T, S>,
extensions?: (Extension | ExtensionFactoryInstance)[],
): InlineContentSpec<T> {
const node = Node.create({
name: inlineContentConfig.type,
Expand Down Expand Up @@ -405,5 +410,6 @@ export function createInlineContentSpec<
);
},
},
extensions,
) as InlineContentSpec<T>;
}
2 changes: 2 additions & 0 deletions packages/core/src/schema/inlineContent/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function createInlineContentSpecFromTipTapNode<
InlineContentImplementation<CustomInlineContentConfig>,
"node"
>,
extensions?: (Extension | ExtensionFactoryInstance)[],
) {
return createInternalInlineContentSpec(
{
Expand All @@ -119,6 +120,7 @@ export function createInlineContentSpecFromTipTapNode<
propSchema: P;
content: "styled" | "none" | "plain";
}>,
extensions,
);
}

Expand Down
Loading