Skip to content

[COMMS-1057] Enable math formula support in BlockNote on documents - #26049

Open
ihordubas99 wants to merge 2 commits into
devfrom
feature/comms-1057-enable-math-formula-support-in-blocknote-on-documents
Open

ihordubas99 wants to merge 2 commits into
devfrom
feature/comms-1057-enable-math-formula-support-in-blocknote-on-documents

Conversation

@ihordubas99

@ihordubas99 ihordubas99 commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Ticket

https://community.openproject.org/wp/COMMS-1057

What are you trying to accomplish?

Documents now support math formulas through @blocknote/math-block. Users can insert a block equation or an inline equation from the slash menu (/math, /equation, /latex) and edit the LaTeX source in a popup. The stored markdown keeps the LaTeX, with $$…$$ for block equations and $…$ for inline ones. The menu texts follow the user's locale.

Screenshots

image

What approach did you choose and why?

Editor. The math block and inline math specs from @blocknote/math-block (0.54.2, matching our BlockNote version) are added to the schema in OpBlockNoteEditor. Their slash menu items are merged into the "Advanced" group with combineByGroup, and the math dictionary of the same locale is merged into the editor dictionary.

Markdown in hocuspocus. The markdown is produced by hocuspocus from its own schema. Without math in that schema, every formula was silently dropped from the stored description. The package's own specs cannot run there, for two reasons. Its entry point imports KaTeX's CSS, which Node cannot load. Its React rendering also leaves work scheduled after ServerBlockNoteEditor tears down its DOM, and that crashes the process. Instead, mathSpecs.ts defines static twins with the same type, content and code meta, like the existing static work package specs. They render a <math> element with an application/x-tex annotation, which BlockNote's markdown exporter turns into $$/$ notation.

KaTeX stylesheet. KaTeX renders every formula twice in the editor, once as HTML and once as MathML for assistive technology, and only its stylesheet hides the MathML copy. Without the stylesheet in the shadow root, the formula shows up twice. Chromium also ignores @font-face rules declared inside a shadow root, so the KaTeX fonts only load when the stylesheet is in the document too. That is why katex.min.css goes into the global styles bundle, which is linked into both the document and the editor's shadow root, instead of the shadow-root-only blocknote bundle. It adds about 23 KB of CSS to every page. The fonts are only fetched where a formula is shown. katex is a direct dependency now, deduped with the version math-block uses.

Left out. Two optional parts of the BlockNote docs are not included.

  • The "Equation" entry in the formatting toolbar's block type select. The toolbar lives in op-blocknote-extensions and cannot take extra items, so this would need a change in the library.
  • LaTeX syntax highlighting in the source popup. It comes with @blocknote/code-block, which COMMS-1058 adds for code block highlighting in a follow-up PR. The math specs already declare latex as their language, so they pick it up without further changes.

Tests

  • hocuspocus unit tests pin the stored markdown for block and inline math.
  • A frontend unit test covers the merged locale.
  • Two feature specs insert both kinds of equation via the slash menu, check that the KaTeX stylesheet applies inside the shadow root, and check the stored markdown. The stylesheet assertion was verified red without the angular.json entry.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@ihordubas99 ihordubas99 self-assigned this Oct 15, 2026
@ihordubas99
ihordubas99 requested a balanced review from Copilot October 15, 2026 12:19
@github-actions

Copy link
Copy Markdown

Dependency Review

The following issues were found:
  • ❌ 1 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ✅ 0 package(s) with unknown licenses.
See the Details below.

Vulnerabilities

frontend/package-lock.json

NameVersionVulnerabilitySeverity
katex0.16.47KaTeX: Existing prototype pollution can bypass trust restrictionslow

OpenSSF Scorecard

PackageVersionScoreDetails
npm/katex 0.16.47 🟢 4.3
Details
CheckScoreReason
Code-Review🟢 5Found 11/21 approved changesets -- score normalized to 5
Maintained🟢 1030 commit(s) and 16 issue activity found in the last 90 days -- score normalized to 10
Security-Policy🟢 10security policy file detected
Dangerous-Workflow⚠️ 0dangerous workflow patterns detected
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Binary-Artifacts🟢 10no binaries found in the repo
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Packaging⚠️ -1packaging workflow not detected
License🟢 10license file detected
Fuzzing⚠️ 0project is not fuzzed
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
Signed-Releases⚠️ 0Project has not signed or included provenance with any releases.
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md
SAST🟢 10SAST tool is run on all commits
npm/@blocknote/math-block 0.54.2 UnknownUnknown
npm/commander 8.3.0 🟢 7.4
Details
CheckScoreReason
Maintained🟢 80 commit(s) and 10 issue activity found in the last 90 days -- score normalized to 8
Security-Policy🟢 10security policy file detected
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Code-Review🟢 9Found 20/22 approved changesets -- score normalized to 9
Binary-Artifacts🟢 10no binaries found in the repo
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Packaging⚠️ -1packaging workflow not detected
Pinned-Dependencies🟢 10all dependencies are pinned
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
License🟢 10license file detected
Fuzzing⚠️ 0project is not fuzzed
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
Signed-Releases⚠️ -1no releases found
SAST🟢 8SAST tool detected but not run on all commits

Scanned Files

  • frontend/package-lock.json

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@ihordubas99
ihordubas99 force-pushed the feature/comms-1057-enable-math-formula-support-in-blocknote-on-documents branch from 2ee4b84 to 751ef64 Compare October 15, 2026 13:05
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./spec/features/components/lookbook_accessibility_spec.rb[1:14:1]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #26049, linked for reference only):

- `rspec ./spec/features/components/lookbook_accessibility_spec.rb[1:14:1]`

Treat this as a standalone task, unrelated to PR #26049. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #26049 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @ihordubas99 to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @ihordubas99, and request a review from @ihordubas99.
On every commit, set @ihordubas99 as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@ihordubas99
ihordubas99 force-pushed the feature/comms-1057-enable-math-formula-support-in-blocknote-on-documents branch from 751ef64 to d1d3f95 Compare October 16, 2026 10:58
@ihordubas99
ihordubas99 marked this pull request as ready for review October 16, 2026 11:26
@github-actions

Copy link
Copy Markdown

Caution

The provided work package version does not match the core version

Details:

Please make sure that:

  • The work package version OR your pull request target branch is correct

@github-actions

Copy link
Copy Markdown

Caution

The Enterprise plan field is not set on the work package

Details:

Please make sure that:

  • The work package Enterprise plan field is set

@ihordubas99
ihordubas99 added this pull request to stack #26127 October 19, 2026 09:33
@ihordubas99
ihordubas99 force-pushed the feature/comms-1057-enable-math-formula-support-in-blocknote-on-documents branch from d1d3f95 to d467c6f Compare October 19, 2026 10:06
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./spec/features/work_packages/table/delete_work_packages_with_descendants_spec.rb[1:1:1]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #26049, linked for reference only):

- `rspec ./spec/features/work_packages/table/delete_work_packages_with_descendants_spec.rb[1:1:1]`

Treat this as a standalone task, unrelated to PR #26049. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #26049 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @ihordubas99 to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @ihordubas99, and request a review from @ihordubas99.
On every commit, set @ihordubas99 as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The KaTeX override forces a deprecated breaking release outside math-block’s declared dependency range.

1 open issue
1 file not reviewed
  • frontend/package-lock.json: Generated file

Review effort: Balanced

Comment thread frontend/package.json
"jquery": "^4.0.0",
"jquery-migrate": "^4.0.2",
"json5": "^2.2.2",
"katex": "^0.18.11",

@judithroth judithroth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Huh, this is again more complex than I hoped for.

Please add a drift guard to the hocuspocus tests:

  • Install @blocknote/math-block as a devDependency.
  • Assert that createMathBlockConfig() and mathInlineContentConfig deep-equal the server specs' configs (type, content, propSchema) that we added

This should prevent (silent) problems on Updates of BlockNote, if they somehow change the config.

I am also unsure about the esbuild addition, but I have to leave now, so you get this as early feedback so far.

Otherwise its quite cool. Saving as Markdown and also copy+paste works 🤩


import { createBlockSpec, createInlineContentSpec, plainContentToString } from "@blocknote/core";

// `@blocknote/math-block` cannot run in Node (it imports KaTeX's CSS, and its React rendering crashes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should report this as a bug. Or at least ask in an issue at BlockNote if they regard it as a bug.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, I reported it: TypeCellOS/BlockNote#3228 and TypeCellOS/BlockNote#3230.

While writing the issues I re-checked it on BlockNote 0.54.2, 0.55.0 and 0.56.0 in a clean project, and it turned out to be two separate problems. The stylesheet import keeps @blocknote/math-block from loading in Node at all, in any mode. The crash after an export is not specific to math-block. It happens with any React custom block in ServerBlockNoteEditor, and only with React's development build, so it would not hit our Docker image (which runs with NODE_ENV=production), but it would hit bin/dev and CI. I made the comment in mathSpecs.ts more precise about that.

// the process after an export), so these mirror its specs. Type, content and `code` must stay in sync
// with the editor, or Yjs content does not map onto this schema. The markdown exporter reads the LaTeX
// from the `application/x-tex` annotation.
function mathElement(latex:string, display:"block" | "inline") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a drift guard to the hocuspocus tests:

  • Install @blocknote/math-block as a devDependency.
  • Assert that createMathBlockConfig() and mathInlineContentConfig deep-equal the server specs' configs (type, content, propSchema).

To ensure that we don't run into inconsistencies on future updates of BlockNote.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. @blocknote/math-block is now a hocuspocus devDependency, and the math tests check that the static specs match its configs and code/defining/isolating meta. They fail as soon as the specs differ. I'll add the same guard to the diagrams PR (#26157).

@ihordubas99
ihordubas99 force-pushed the feature/comms-1057-enable-math-formula-support-in-blocknote-on-documents branch 2 times, most recently from 2c497a4 to b1082d1 Compare October 22, 2026 12:29
@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./spec/features/work_packages/cancel_editing_spec.rb[1:5]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #26049, linked for reference only):

- `rspec ./spec/features/work_packages/cancel_editing_spec.rb[1:5]`

Treat this as a standalone task, unrelated to PR #26049. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #26049 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @ihordubas99 to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @ihordubas99, and request a review from @ihordubas99.
On every commit, set @ihordubas99 as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@ihordubas99
ihordubas99 force-pushed the feature/comms-1057-enable-math-formula-support-in-blocknote-on-documents branch from b1082d1 to c9a5997 Compare October 26, 2026 11:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants