Repository navigation
[COMMS-1057] Enable math formula support in BlockNote on documents - #26049
ihordubas99 wants to merge 2 commits into
Conversation
Dependency ReviewThe following issues were found:
Vulnerabilitiesfrontend/package-lock.json
OpenSSF Scorecard
Scanned Files
|
There was a problem hiding this comment.
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.
2ee4b84 to
751ef64
Compare
|
Warning Flaky specs
🤖 Ask Copilot to investigateCopy 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. |
751ef64 to
d1d3f95
Compare
|
Caution The provided work package version does not match the core version Details:
Please make sure that:
|
|
Caution The Enterprise plan field is not set on the work package Details:
Please make sure that:
|
d1d3f95 to
d467c6f
Compare
|
Warning Flaky specs
🤖 Ask Copilot to investigateCopy 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. |
| "jquery": "^4.0.0", | ||
| "jquery-migrate": "^4.0.2", | ||
| "json5": "^2.2.2", | ||
| "katex": "^0.18.11", |
judithroth
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
2c497a4 to
b1082d1
Compare
|
Warning Flaky specs
🤖 Ask Copilot to investigateCopy 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. |
b1082d1 to
c9a5997
Compare

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
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 inOpBlockNoteEditor. Their slash menu items are merged into the "Advanced" group withcombineByGroup, 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
ServerBlockNoteEditortears down its DOM, and that crashes the process. Instead,mathSpecs.tsdefines static twins with the same type, content andcodemeta, like the existing static work package specs. They render a<math>element with anapplication/x-texannotation, 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-facerules declared inside a shadow root, so the KaTeX fonts only load when the stylesheet is in the document too. That is whykatex.min.cssgoes into the globalstylesbundle, which is linked into both the document and the editor's shadow root, instead of the shadow-root-onlyblocknotebundle. It adds about 23 KB of CSS to every page. The fonts are only fetched where a formula is shown.katexis a direct dependency now, deduped with the version math-block uses.Left out. Two optional parts of the BlockNote docs are not included.
@blocknote/code-block, which COMMS-1058 adds for code block highlighting in a follow-up PR. The math specs already declarelatexas their language, so they pick it up without further changes.Tests
angular.jsonentry.Merge checklist