Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e3f182a
Added `renderPreview` field to code block options and added LaTeX pre…
matthewlipski Jun 9, 2026
6ccc955
Math block overhaul
matthewlipski Jun 16, 2026
ae49edc
Small fix
matthewlipski Jun 16, 2026
9687742
Implemented minor CodeRabbit feedback
matthewlipski Jun 16, 2026
9626d7e
Updated test snapshot
matthewlipski Jun 16, 2026
de7b1df
Big update to math block
matthewlipski Jun 18, 2026
719fd7a
Merge branch 'main' into code-block-previews
matthewlipski Jun 18, 2026
ed8c681
Major changes
matthewlipski Jun 23, 2026
c8388cc
Fixed build issue
matthewlipski Jun 23, 2026
f2bfe62
Reverted `inert`
matthewlipski Jun 23, 2026
57c459a
Implemented PR feedback
matthewlipski Jun 23, 2026
3a1e4ca
Fixed test editor having unsupported default language for code block
matthewlipski Jun 23, 2026
ed8e6c1
Fixed export error
matthewlipski Jun 23, 2026
ce99770
Removed FloatingUI positioning from math block popup
matthewlipski Jun 24, 2026
d6d1d46
Moved keyboard & selection handling to extension
matthewlipski Jun 24, 2026
aa666bc
Added React math block
matthewlipski Jun 25, 2026
b2bfd98
feat(core): de-duplicate and order extensions by key in ExtensionManager
nperez0111 Jun 29, 2026
30d174e
Merge branch 'sub-extensions' into code-block-previews
nperez0111 Jun 29, 2026
54522f2
refactor: move syntax highlighting to singleton extension, code-block…
nperez0111 Jun 29, 2026
d1b52d2
feat: Math inline content (#2878)
matthewlipski Jun 30, 2026
98eddb3
Refactored math block/inline content to have the same structure
matthewlipski Jun 30, 2026
2d53854
Small fixes
matthewlipski Jun 30, 2026
3e18e85
Added input rules and removed old katex dep from code block
matthewlipski Jun 30, 2026
f5ba0b1
Changed `Prosemirror-selectednode` element
matthewlipski Jul 1, 2026
e560634
Added exporters
matthewlipski Jul 1, 2026
bec3550
Fixed vertical arrow key presses unexpectedly moving selection to inl…
matthewlipski Jul 1, 2026
ba71b7f
Fixed inline content copying/parsing
matthewlipski Jul 2, 2026
d5d59fb
Fixed light mode popup default text color
matthewlipski Jul 2, 2026
91031a9
Added better up/down arrow handling to inline content
matthewlipski Jul 2, 2026
0a7a663
Added inline content tests
matthewlipski Jul 2, 2026
0517c90
Made backspace/delete remove math block when popup is closed
matthewlipski Jul 2, 2026
c048296
Added OK button to popup & fixed overflow behavior
matthewlipski Jul 2, 2026
2ac3ef8
Added tests
matthewlipski Jul 2, 2026
392e7ba
Updated example slash menu items
matthewlipski Jul 4, 2026
e5c4051
Made popups close on editor blur
matthewlipski Jul 4, 2026
83ee1f4
Fixed formatting toolbar showing in inline math
matthewlipski Jul 6, 2026
0773c60
Adjusted selected node styling
matthewlipski Jul 6, 2026
7469662
Mermaid block (#2886)
YousefED Jul 7, 2026
90c8af9
Converted vanilla math block tests to React
matthewlipski Jul 7, 2026
150376d
Removed vanilla math block and reverted code block to not support pre…
matthewlipski Jul 7, 2026
07824ab
Simplified directories
matthewlipski Jul 7, 2026
7265742
Made popup get positioned using CSS anchors
matthewlipski Jul 8, 2026
08a66fb
try fix playground deployment
YousefED Jul 8, 2026
2291106
fix ci?
YousefED Jul 8, 2026
4ac6eaf
Made selected block styling appear as an overlay
matthewlipski Jul 8, 2026
c647b01
Implemented PR feedback
matthewlipski Jul 8, 2026
62013eb
refactor: make syntax highlighting a user-provided extension; error o…
nperez0111 Jul 9, 2026
5aacda4
Merge branch 'code-block-previews' into syntax-highlighting
nperez0111 Jul 9, 2026
042a4b1
refactor: make SourceBlockWithPreview a singleton; add inline syntax …
nperez0111 Jul 9, 2026
1685083
Merge remote-tracking branch 'origin/main' into code-block-previews
nperez0111 Jul 9, 2026
16bd539
Merge branch 'code-block-previews' into syntax-highlighting
nperez0111 Jul 9, 2026
b4dd942
Overhauled CSS
matthewlipski Jul 10, 2026
f27f1fe
Merge remote-tracking branch 'origin/code-block-previews' into code-b…
matthewlipski Jul 10, 2026
d9155ea
Merge pull request #2873 from TypeCellOS/syntax-highlighting
YousefED Jul 11, 2026
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
49 changes: 38 additions & 11 deletions docs/content/docs/features/blocks/code-blocks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type CodeBlockOptions = {
aliases?: string[];
}
>;
createHighlighter?: () => Promise<HighlighterGeneric<any, any>>;
};
```

Expand All @@ -44,15 +43,36 @@ type CodeBlockOptions = {

`supportedLanguages:` The syntax highlighting languages supported by the code block, which is an empty array by default.

`createHighlighter:` The [Shiki highliter](https://shiki.style/guide/load-theme) to use for syntax highlighting.
**Syntax Highlighting**

BlockNote also provides a generic set of options for syntax highlighting in the `@blocknote/code-block` package, which support a wide range of languages:
Syntax highlighting is handled by a separate editor extension that you add to the editor's `extensions` (not configured on the code block itself), so it can highlight any block that declares a language — the code block, and blocks like the math block. When the extension isn't added, those blocks render as plain text.

The extension is configured with a Shiki highlighter:

```ts
import { createCodeBlockSpec } from "@blocknote/core";
import { codeBlockOptions } from "@blocknote/code-block";
type SyntaxHighlightingOptions = {
createHighlighter: () => Promise<HighlighterGeneric<any, any>>;
};
```

`createHighlighter:` The [Shiki highlighter](https://shiki.style/guide/load-theme) to use for syntax highlighting.

Which blocks get highlighted (and as which language) is decided by each block's spec via its `meta.highlight` callback — the code block highlights as its `language` prop, the math block always as `latex` — so you don't configure this on the extension.

const codeBlock = createCodeBlockSpec(codeBlockOptions);
BlockNote provides a generic, ready-to-use highlighter in the `@blocknote/code-block` package, which supports a wide range of languages. It's exported as a pre-configured `syntaxHighlighter` extension, alongside the code block options:

```ts
import { createCodeBlockSpec } from "@blocknote/core";
import { codeBlockOptions, syntaxHighlighter } from "@blocknote/code-block";

const editor = useCreateBlockNote({
extensions: [syntaxHighlighter],
schema: BlockNoteSchema.create().extend({
blockSpecs: {
codeBlock: createCodeBlockSpec(codeBlockOptions),
},
}),
});
```

See [this example](/examples/theming/code-block) to see it in action.
Expand Down Expand Up @@ -88,10 +108,22 @@ This will generate a `shiki.bundle.ts` file that you can use to create a syntax
Like this:

```ts
import { SyntaxHighlightingExtension } from "@blocknote/core";
import { createHighlighter } from "./shiki.bundle.js";

// Build a syntax highlighter extension from your custom Shiki bundle, then add
// it to the editor's `extensions`.
const syntaxHighlighter = SyntaxHighlightingExtension({
createHighlighter: () =>
createHighlighter({
themes: ["light-plus", "dark-plus"],
langs: [],
}),
});

export default function App() {
const editor = useCreateBlockNote({
extensions: [syntaxHighlighter],
schema: BlockNoteSchema.create().extend({
blockSpecs: {
codeBlock: createCodeBlockSpec({
Expand All @@ -103,11 +135,6 @@ export default function App() {
aliases: ["ts"],
},
},
createHighlighter: () =>
createHighlighter({
themes: ["light-plus", "dark-plus"],
langs: [],
}),
}),
},
}),
Expand Down
10 changes: 8 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@polar-sh/sdk": "^0.42.2",
"@react-email/components": "^1.0.4",
"@react-email/render": "^2.0.4",
"@react-pdf/renderer": "^4.3.0",
"@react-pdf/renderer": "^4.5.1",
"@sentry/nextjs": "^10.34.0",
"@shikijs/core": "^4",
"@shikijs/engine-javascript": "^4",
Expand Down Expand Up @@ -96,7 +96,13 @@
"tailwind-merge": "^3.4.0",
"y-partykit": "^0.0.25",
"yjs": "^13.6.27",
"zod": "^4.3.5"
"zod": "^4.3.5",
"@blocknote/math-block": "workspace:*",
"mermaid": "^11.0.0",
"@blocknote/diagram-block": "workspace:*",
"docx": "^9.6.1",
"@react-pdf/math": "^2.0.1",
"katex": "^0.16.11"
},
"devDependencies": {
"@blocknote/code-block": "workspace:*",
Expand Down
8 changes: 6 additions & 2 deletions examples/04-theming/06-code-block/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useCreateBlockNote } from "@blocknote/react";
// This packages some of the most used languages in on-demand bundle
import { codeBlockOptions } from "@blocknote/code-block";
// This packages some of the most used languages in on-demand bundle, and a
// ready-to-use syntax highlighter extension configured with them.
import { codeBlockOptions, syntaxHighlighter } from "@blocknote/code-block";

export default function App() {
// Creates a new editor instance.
const editor = useCreateBlockNote({
// Adding the syntax highlighter extension enables syntax highlighting for
// the code block. Without it, code renders as plain text.
extensions: [syntaxHighlighter],
schema: BlockNoteSchema.create().extend({
blockSpecs: {
codeBlock: createCodeBlockSpec(codeBlockOptions),
Expand Down
25 changes: 18 additions & 7 deletions examples/04-theming/07-custom-code-block/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import { BlockNoteSchema, createCodeBlockSpec } from "@blocknote/core";
import {
BlockNoteSchema,
createCodeBlockSpec,
SyntaxHighlightingExtension,
} from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useCreateBlockNote } from "@blocknote/react";
// Bundle created from `npx shiki-codegen --langs typescript,javascript,react --themes light-plus,dark-plus --engine javascript --precompiled ./shiki.bundle.ts`
import { createHighlighter } from "./shiki.bundle";

// Syntax highlighting is a separate extension, configured with a highlighter.
// Here we build one from our own custom Shiki bundle (with `dark-plus` /
// `light-plus` themes) and pass it to the editor's `extensions` below.
const syntaxHighlighter = SyntaxHighlightingExtension({
// This creates a highlighter, it can be asynchronous to load it afterwards
createHighlighter: () =>
createHighlighter({
themes: ["dark-plus", "light-plus"],
langs: [],
}),
});

export default function App() {
// Creates a new editor instance.
const editor = useCreateBlockNote({
extensions: [syntaxHighlighter],
schema: BlockNoteSchema.create().extend({
blockSpecs: {
codeBlock: createCodeBlockSpec({
Expand All @@ -27,12 +44,6 @@ export default function App() {
name: "Vue",
},
},
// This creates a highlighter, it can be asynchronous to load it afterwards
createHighlighter: () =>
createHighlighter({
themes: ["dark-plus", "light-plus"],
langs: [],
}),
}),
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
"playground": true,
"docs": true,
"author": "yousefed",
"tags": ["Interoperability"],
"tags": [
"Interoperability"
],
"dependencies": {
"@blocknote/xl-pdf-exporter": "latest",
"@blocknote/diagram-block": "latest",
"@blocknote/math-block": "latest",
"@blocknote/xl-multi-column": "latest",
"@react-pdf/renderer": "^4.3.0"
"@blocknote/xl-pdf-exporter": "latest",
"@react-pdf/math": "^2.0.1",
"@react-pdf/renderer": "^4.5.1"
},
"pro": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
"@mantine/hooks": "^9.0.2",
"react": "^19.2.3",
"react-dom": "^19.2.3",
"@blocknote/xl-pdf-exporter": "latest",
"@blocknote/diagram-block": "latest",
"@blocknote/math-block": "latest",
"@blocknote/xl-multi-column": "latest",
"@react-pdf/renderer": "^4.3.0"
"@blocknote/xl-pdf-exporter": "latest",
"@react-pdf/math": "^2.0.1",
"@react-pdf/renderer": "^4.5.1"
},
"devDependencies": {
"@types/react": "^19.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import "@blocknote/core/fonts/inter.css";
import * as locales from "@blocknote/core/locales";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { createReactDiagramBlockSpec } from "@blocknote/diagram-block";
import {
createReactInlineMathSpec,
createReactMathBlockSpec,
} from "@blocknote/math-block";
import {
SuggestionMenuController,
getDefaultReactSlashMenuItems,
Expand All @@ -24,6 +29,8 @@ import {
PDFExporter,
pdfDefaultSchemaMappings,
} from "@blocknote/xl-pdf-exporter";
import { diagramBlockMapping } from "@blocknote/xl-pdf-exporter/diagram-block";
import { mathBlockMapping } from "@blocknote/xl-pdf-exporter/math-block";
import { pdf, PDFViewer } from "@react-pdf/renderer";
import { JSX, useEffect, useMemo, useReducer, useState } from "react";

Expand All @@ -38,7 +45,16 @@ export default function App() {
// Creates a new editor instance.
const editor = useCreateBlockNote({
// Adds support for page breaks & multi-column blocks.
schema: withMultiColumn(withPageBreak(BlockNoteSchema.create())),
// Adds support for math & diagram blocks.
schema: withMultiColumn(withPageBreak(BlockNoteSchema.create())).extend({
blockSpecs: {
math: createReactMathBlockSpec(),
diagram: createReactDiagramBlockSpec(),
},
inlineContentSpecs: {
inlineMath: createReactInlineMathSpec(),
},
}),
dropCursor: multiColumnDropCursor,
dictionary: {
...locales.en,
Expand Down Expand Up @@ -330,6 +346,31 @@ export default function App() {
console.log("Hello World", message);
};`,
},
{
type: "math",
content: "a^2 = \\sqrt{b^2 + c^2}",
},
{
type: "diagram",
content: `graph TD
A[Start] --> B{Works?}
B -->|Yes| C[Ship it]
B -->|No| A`,
},
{
type: "paragraph",
content: [
{
type: "text",
text: "Inline math: ",
styles: {},
},
{
type: "inlineMath",
content: "e^{i\\pi} + 1 = 0",
},
],
},
{
type: "columnList",
children: [
Expand Down Expand Up @@ -402,7 +443,16 @@ export default function App() {

// Exports the editor document to PDF whenever it changes.
const onChange = async () => {
const exporter = new PDFExporter(editor.schema, pdfDefaultSchemaMappings);
const exporter = new PDFExporter(editor.schema, {
...pdfDefaultSchemaMappings,
blockMapping: {
...pdfDefaultSchemaMappings.blockMapping,
// Embeds diagrams as images instead of their Mermaid source.
diagram: diagramBlockMapping,
// Renders math blocks as formulas instead of their LaTeX source.
math: mathBlockMapping,
},
});
const pdfDocument = await exporter.toReactPDFDocument(editor.document);
setPDFDocument(pdfDocument);
forceRerender();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
"playground": true,
"docs": true,
"author": "yousefed",
"tags": [""],
"tags": [
""
],
"dependencies": {
"@blocknote/diagram-block": "latest",
"@blocknote/math-block": "latest",
"@blocknote/xl-docx-exporter": "latest",
"@blocknote/xl-multi-column": "latest"
"@blocknote/xl-multi-column": "latest",
"katex": "^0.16.11"
},
"pro": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
"@mantine/hooks": "^9.0.2",
"react": "^19.2.3",
"react-dom": "^19.2.3",
"@blocknote/diagram-block": "latest",
"@blocknote/math-block": "latest",
"@blocknote/xl-docx-exporter": "latest",
"@blocknote/xl-multi-column": "latest"
"@blocknote/xl-multi-column": "latest",
"katex": "^0.16.11"
},
"devDependencies": {
"@types/react": "^19.2.3",
Expand Down
Loading
Loading