Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ updates:
- dependency-name: "@tiptap/extension-code"
- dependency-name: "@tiptap/extension-horizontal-rule"
- dependency-name: "@tiptap/extension-italic"
- dependency-name: "@tiptap/extension-link"

- dependency-name: "@tiptap/extension-paragraph"
- dependency-name: "@tiptap/extension-strike"
- dependency-name: "@tiptap/extension-text"
Expand Down
49 changes: 49 additions & 0 deletions docs/content/docs/features/blocks/inline-content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,55 @@ type Link = {
};
```

### Customizing Links
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also make sure this is reflected correctly in blocknote initialization options?

Looking at it, that part is actually currently broken in docs: https://www.blocknotejs.org/docs/reference/editor/overview#options

(maybe check for other AutoTypeTables that are broken as well)


You can customize how links are rendered and how they respond to clicks with the `links` editor option.

```ts
const editor = BlockNoteEditor.create({
links: {
HTMLAttributes: {
class: "my-link-class",
target: "_blank",
},
onClick: (event) => {
// Custom click logic, e.g. routing without a page reload.
},
},
});
```

#### `HTMLAttributes`

Additional HTML attributes that should be added to rendered link elements.

```ts
const editor = BlockNoteEditor.create({
links: {
HTMLAttributes: {
class: "my-link-class",
target: "_blank",
},
},
});
```

#### `onClick`

Custom handler invoked when a link is clicked. If left `undefined`, links are opened in a new window on click (the default behavior). If provided, that default behavior is disabled and this function is called instead.

Returning `false` will let BlockNote run other click handlers after this one. Returning `true` or nothing (the default) marks the event as handled.

```ts
const editor = BlockNoteEditor.create({
links: {
onClick: (event) => {
// Do something when a link is clicked.
},
},
});
```

## Default Styles

The default text formatting options in BlockNote are represented by the `Styles` in the default schema:
Expand Down
40 changes: 27 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,7 @@
],
"overrides": {
"vitest": "4.1.2",
"@vitest/runner": "4.1.2",
"msw": "2.11.5",
"ai": "6.0.5",
"@ai-sdk/anthropic": "3.0.2",
"@ai-sdk/openai": "3.0.2",
"@ai-sdk/groq": "3.0.2",
"@ai-sdk/google": "3.0.2",
"@ai-sdk/mistral": "3.0.2",
"@ai-sdk/openai-compatible": "2.0.2",
"@ai-sdk/provider-utils": "4.0.2",
"@ai-sdk/react": "3.0.5",
"@ai-sdk/gateway": "3.0.4"
"@vitest/runner": "4.1.2"
}
},
"packageManager": "pnpm@10.23.0+sha512.21c4e5698002ade97e4efe8b8b4a89a8de3c85a37919f957e7a0f30f38fbc5bbdd05980ffe29179b2fb6e6e691242e098d945d1601772cad0fef5fb6411e2a4b",
Expand All @@ -71,5 +60,30 @@
"start": "serve playground/dist -c ../serve.json",
"test": "nx run-many --target=test",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css,scss,md}\""
}
},
"overrides": {
"msw": "2.11.5",
"ai": "6.0.5",
"@ai-sdk/anthropic": "3.0.2",
"@ai-sdk/openai": "3.0.2",
"@ai-sdk/groq": "3.0.2",
"@ai-sdk/google": "3.0.2",
"@ai-sdk/mistral": "3.0.2",
"@ai-sdk/openai-compatible": "2.0.2",
"@ai-sdk/provider-utils": "4.0.2",
"@ai-sdk/react": "3.0.5",
"@ai-sdk/gateway": "3.0.4",
"@headlessui/react": "^2.2.4",
"@tiptap/core": "^3.0.0",
"@tiptap/pm": "^3.0.0"
},
"workspaces": [
"packages/*",
"examples/*/*",
"playground",
"fumadocs",
"docs",
"shared",
"tests"
]
}
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"@tiptap/extension-code": "^3.13.0",
"@tiptap/extension-horizontal-rule": "^3.13.0",
"@tiptap/extension-italic": "^3.13.0",
"@tiptap/extension-link": "^3.22.1",
"@tiptap/extension-paragraph": "^3.13.0",
"@tiptap/extension-strike": "^3.13.0",
"@tiptap/extension-text": "^3.13.0",
Expand Down
20 changes: 6 additions & 14 deletions packages/core/src/api/nodeConversions/blockToNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,20 @@ function styledTextToNodes<T extends StyleSchema>(

/**
* Converts a Link inline content element to
* prosemirror text nodes with the appropriate marks
* prosemirror text nodes with the link mark applied.
*/
function linkToNodes(
link: PartialLink<StyleSchema>,
schema: Schema,
styleSchema: StyleSchema,
): Node[] {
const linkMark = schema.marks.link.create({
href: link.href,
});
const linkMark = schema.marks.link.create({ href: link.href });

return styledTextArrayToNodes(link.content, schema, styleSchema).map(
(node) => {
if (node.type.name === "text") {
return node.mark([...node.marks, linkMark]);
}

if (node.type.name === "hardBreak") {
return node;
}
throw new Error("unexpected node type");
},
(node) =>
node.type.name === "text"
? node.mark([...node.marks, linkMark])
: node,
);
}

Expand Down
Loading