-
-
Notifications
You must be signed in to change notification settings - Fork 760
feat: math block #2857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matthewlipski
wants to merge
75
commits into
main
Choose a base branch
from
code-block-previews
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: math block #2857
Changes from 3 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
e3f182a
Added `renderPreview` field to code block options and added LaTeX pre…
matthewlipski 6ccc955
Math block overhaul
matthewlipski ae49edc
Small fix
matthewlipski 9687742
Implemented minor CodeRabbit feedback
matthewlipski 9626d7e
Updated test snapshot
matthewlipski de7b1df
Big update to math block
matthewlipski 719fd7a
Merge branch 'main' into code-block-previews
matthewlipski ed8c681
Major changes
matthewlipski c8388cc
Fixed build issue
matthewlipski f2bfe62
Reverted `inert`
matthewlipski 57c459a
Implemented PR feedback
matthewlipski 3a1e4ca
Fixed test editor having unsupported default language for code block
matthewlipski ed8e6c1
Fixed export error
matthewlipski ce99770
Removed FloatingUI positioning from math block popup
matthewlipski d6d1d46
Moved keyboard & selection handling to extension
matthewlipski aa666bc
Added React math block
matthewlipski b2bfd98
feat(core): de-duplicate and order extensions by key in ExtensionManager
nperez0111 30d174e
Merge branch 'sub-extensions' into code-block-previews
nperez0111 54522f2
refactor: move syntax highlighting to singleton extension, code-block…
nperez0111 d1b52d2
feat: Math inline content (#2878)
matthewlipski 98eddb3
Refactored math block/inline content to have the same structure
matthewlipski 2d53854
Small fixes
matthewlipski 3e18e85
Added input rules and removed old katex dep from code block
matthewlipski f5ba0b1
Changed `Prosemirror-selectednode` element
matthewlipski e560634
Added exporters
matthewlipski bec3550
Fixed vertical arrow key presses unexpectedly moving selection to inl…
matthewlipski ba71b7f
Fixed inline content copying/parsing
matthewlipski d5d59fb
Fixed light mode popup default text color
matthewlipski 91031a9
Added better up/down arrow handling to inline content
matthewlipski 0a7a663
Added inline content tests
matthewlipski 0517c90
Made backspace/delete remove math block when popup is closed
matthewlipski c048296
Added OK button to popup & fixed overflow behavior
matthewlipski 2ac3ef8
Added tests
matthewlipski 392e7ba
Updated example slash menu items
matthewlipski e5c4051
Made popups close on editor blur
matthewlipski 83ee1f4
Fixed formatting toolbar showing in inline math
matthewlipski 0773c60
Adjusted selected node styling
matthewlipski 7469662
Mermaid block (#2886)
YousefED 90c8af9
Converted vanilla math block tests to React
matthewlipski 150376d
Removed vanilla math block and reverted code block to not support pre…
matthewlipski 07824ab
Simplified directories
matthewlipski 7265742
Made popup get positioned using CSS anchors
matthewlipski 08a66fb
try fix playground deployment
YousefED 2291106
fix ci?
YousefED 4ac6eaf
Made selected block styling appear as an overlay
matthewlipski c647b01
Implemented PR feedback
matthewlipski 62013eb
refactor: make syntax highlighting a user-provided extension; error o…
nperez0111 5aacda4
Merge branch 'code-block-previews' into syntax-highlighting
nperez0111 042a4b1
refactor: make SourceBlockWithPreview a singleton; add inline syntax …
nperez0111 1685083
Merge remote-tracking branch 'origin/main' into code-block-previews
nperez0111 16bd539
Merge branch 'code-block-previews' into syntax-highlighting
nperez0111 b4dd942
Overhauled CSS
matthewlipski f27f1fe
Merge remote-tracking branch 'origin/code-block-previews' into code-b…
matthewlipski d9155ea
Merge pull request #2873 from TypeCellOS/syntax-highlighting
YousefED 1ba15b2
Merge branch 'main' into code-block-previews
matthewlipski a7985d5
Changed diagram/math to use plain text
matthewlipski 2cbb741
Revert "Changed diagram/math to use plain text"
matthewlipski a7aa19a
Updated e2e screenshots
matthewlipski 062f026
fix: Plain content issues (#2896)
matthewlipski b15ed5f
Merge branch 'main' into code-block-previews
matthewlipski eefc76e
Small fixes
matthewlipski b5cfa16
Converted blocks/inline content to plain text
matthewlipski 6530d4d
Fixed Enter/Shift+Enter handling
matthewlipski e0ccbcb
Fixed syntax highlighting
matthewlipski 66e3373
Fixed tests
matthewlipski 40d96c6
Merge branch 'main' into code-block-previews
matthewlipski 9240888
Fixed tests
matthewlipski d3fa61b
Fixed e2e tests
matthewlipski e7b952e
Removed case in formatting toolbar extension to not show when selecti…
matthewlipski 0924f32
Added docs
matthewlipski e35d627
try fix ci
YousefED c93d94d
Fixed math blocks erroring in prod builds: patch katex lexer strings …
YousefED b32ea3b
Made math block/inline content show error message in the error placeh…
matthewlipski 98b5d2e
Fixed formatting toolbar regression
matthewlipski 2f6f305
Updated docs
matthewlipski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "playground": true, | ||
| "docs": true, | ||
| "author": "matthewlipski", | ||
| "tags": ["Intermediate", "Blocks", "Custom Schemas"], | ||
| "dependencies": { | ||
| "@blocknote/code-block": "latest", | ||
| "@blocknote/math-block": "latest" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Math Block | ||
|
|
||
| In this example, we register the `@blocknote/math-block` block in a custom schema. The math block renders LaTeX as MathML (using Temml) for the browser to display natively, and reveals an editable LaTeX source popup when selected. Exporting to HTML produces a MathML `<math>` element, and pasting MathML back in is converted to LaTeX. | ||
|
|
||
| **Try it out:** Click a formula to edit its LaTeX! | ||
|
|
||
| **Relevant Docs:** | ||
|
|
||
| - [Custom Blocks](/docs/features/custom-schemas/custom-blocks) | ||
| - [Editor Setup](/docs/getting-started/editor-setup) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <html lang="en"> | ||
|
matthewlipski marked this conversation as resolved.
|
||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Math Block</title> | ||
| <script> | ||
| <!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY --> | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="./main.tsx"></script> | ||
| </body> | ||
| </html> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY | ||
| import React from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import App from "./src/App.jsx"; | ||
|
matthewlipski marked this conversation as resolved.
|
||
|
|
||
| const root = createRoot(document.getElementById("root")!); | ||
| root.render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode>, | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "name": "@blocknote/example-custom-schema-math-block", | ||
| "description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY", | ||
| "type": "module", | ||
| "private": true, | ||
| "version": "0.12.4", | ||
| "scripts": { | ||
| "start": "vp dev", | ||
| "dev": "vp dev", | ||
| "build:prod": "tsc && vp build", | ||
| "preview": "vp preview" | ||
| }, | ||
| "dependencies": { | ||
| "@blocknote/ariakit": "latest", | ||
| "@blocknote/core": "latest", | ||
| "@blocknote/mantine": "latest", | ||
| "@blocknote/react": "latest", | ||
| "@blocknote/shadcn": "latest", | ||
| "@mantine/core": "^9.0.2", | ||
| "@mantine/hooks": "^9.0.2", | ||
| "react": "^19.2.3", | ||
| "react-dom": "^19.2.3", | ||
| "@blocknote/code-block": "latest", | ||
| "@blocknote/math-block": "latest" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^19.2.3", | ||
| "@types/react-dom": "^19.2.3", | ||
| "@vitejs/plugin-react": "^6.0.1", | ||
| "vite-plus": "catalog:" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import "@blocknote/core/fonts/inter.css"; | ||
| import { BlockNoteSchema } from "@blocknote/core"; | ||
| import { createHighlighter } from "@blocknote/code-block"; | ||
| import { createMathBlockSpec } from "@blocknote/math-block"; | ||
| import { BlockNoteView } from "@blocknote/mantine"; | ||
| import "@blocknote/mantine/style.css"; | ||
| import { useCreateBlockNote } from "@blocknote/react"; | ||
|
|
||
| export default function App() { | ||
| // The math block isn't a default block, so we register it in a custom schema. | ||
| const editor = useCreateBlockNote({ | ||
| // The Shiki highlighter (from @blocknote/code-block) syntax-highlights the | ||
| // math block's editable LaTeX source popup. `highlightBlock` enables it for | ||
| // the math block and highlights it as LaTeX. | ||
| syntaxHighlighting: { | ||
| createHighlighter, | ||
| highlightBlock: (block) => | ||
| block.type === "math" ? "latex" : block.props.language, | ||
| }, | ||
| schema: BlockNoteSchema.create().extend({ | ||
| blockSpecs: { | ||
| math: createMathBlockSpec(), | ||
| }, | ||
| }), | ||
| initialContent: [ | ||
| { | ||
| type: "paragraph", | ||
| content: "Click a formula to edit its LaTeX source:", | ||
| }, | ||
| { | ||
| type: "math", | ||
| content: "a^2 = \\sqrt{b^2 + c^2}", | ||
| }, | ||
| { | ||
| type: "math", | ||
| content: "\\int_0^\\infty e^{-x^2} dx = \\frac{\\sqrt{\\pi}}{2}", | ||
| }, | ||
| { | ||
| type: "paragraph", | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| // Renders the editor instance using a React component. | ||
| return <BlockNoteView editor={editor} />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "__comment": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY", | ||
| "compilerOptions": { | ||
| "target": "ESNext", | ||
| "useDefineForClassFields": true, | ||
| "lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
| "allowJs": false, | ||
| "skipLibCheck": true, | ||
| "allowSyntheticDefaultImports": true, | ||
| "strict": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "module": "ESNext", | ||
| "moduleResolution": "bundler", | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "noEmit": true, | ||
| "jsx": "react-jsx", | ||
| "composite": true | ||
| }, | ||
| "include": ["."], | ||
| "__ADD_FOR_LOCAL_DEV_references": [ | ||
| { | ||
| "path": "../../../packages/core/" | ||
| }, | ||
| { | ||
| "path": "../../../packages/react/" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY | ||
| import react from "@vitejs/plugin-react"; | ||
| import * as fs from "fs"; | ||
| import * as path from "path"; | ||
| import { defineConfig } from "vite-plus"; | ||
| // https://vitejs.dev/config/ | ||
| export default defineConfig(((conf: { command: string }) => ({ | ||
| plugins: [react()], | ||
| optimizeDeps: {}, | ||
| build: { | ||
| sourcemap: true, | ||
| }, | ||
| resolve: { | ||
| alias: | ||
| conf.command === "build" || | ||
| !fs.existsSync(path.resolve(__dirname, "../../packages/core/src")) | ||
| ? {} | ||
| : ({ | ||
| // Comment out the lines below to load a built version of blocknote | ||
| // or, keep as is to load live from sources with live reload working | ||
| "@blocknote/core": path.resolve( | ||
| __dirname, | ||
| "../../packages/core/src/", | ||
| ), | ||
| "@blocknote/react": path.resolve( | ||
| __dirname, | ||
| "../../packages/react/src/", | ||
|
matthewlipski marked this conversation as resolved.
|
||
| ), | ||
| } as any), | ||
| }, | ||
| })) as Parameters<typeof defineConfig>[0]); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.