Repository navigation
fix(math-block): export the source of a formula that does not compile - #3389
Conversation
…s text
A math block with a formula that KaTeX cannot render (for example
"\frac{1}{", a state that a user makes with each keystroke) stopped the
external HTML export and the Markdown export of the full document:
"Cannot read properties of null (reading 'classList')". Inline math with
such a formula was not in the export, without an error.
Cause: for such a formula, the output of KaTeX has no math element. The
adapter latexToMathMLElement had a cast that hid this case. The
components for the external HTML then rendered nothing, and the
serializer of core needs an element for each block.
Fix: latexToMathMLElement now returns a result type, as latexToMathML
of the other exporters does: the element, or a typed error if KaTeX has
no MathML for the formula. Thus the compiler makes each caller handle
that case. The new function mathMLExportContent gives the content of
the math element for the two cases. Without MathML from KaTeX, the
content is an merror element with the source as text, and the
application/x-tex annotation with the source. Thus, the HTML parse
reads the formula back as the same block (or inline content) with the
same source, and the Markdown export writes the source between dollar
signs, as for a formula that compiles.
Not changed: a formula that KaTeX renders in part (for example
"x \badcommand y", with the unknown command in red) exports its MathML
as before.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/diagram-block
@blocknote/mantine
@blocknote/math-block
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
@blocknote/xl-typst-exporter
commit: |
|
Main has the new test layout (tests/src/integration, Node or browser tests, setupEditor) and the Knip audit. Conflicts in 21 files: - package.json: the devDependencies of main (knip, postcss), and the two of the lens (@vitest/coverage-v8, eslint-plugin-perfectionist). - packages/xl-ai/package.json: the dependencies of main (no headers-polyfill), and the text-lens exports and the Yjs 14 peers of the lens. - packages/xl-ai/vitestSetup.ts: the version of main (getTestOptionsHost works without a window too). - vite.config.ts: the lint config of main, and the lens plugins and the two lens overrides. The lens override also has the rule of main that forbids an import of a test file. - Table/block.ts: the colwidth helper of the lens, with the colspan limit of main (as in the merge of 21 November). - defaultBlocks.ts: the imports of the two sides. - createLinkWithCaption.ts: the version of the lens. Main has only the half without a caption (#3387); the lens also writes a figure for a caption. - math-block (3 files): the version of main (#3389, the reviewed form of the lens commit 82b18c6). The three test files of that lens commit stay. Three of their cases expect an merror for a formula that KaTeX renders in part (x \badcommand y). Main keeps the MathML of KaTeX for such a formula, thus these three cases fail. - BlockNoteEditor.test.ts (removed by main): the block ID tests of the lens move to BlockNoteEditor.node.test.ts (headless) and BlockNoteEditor.browser.test.ts (mounted), with setupEditor. - DiffVersioningExtension.test.ts, utils.test.ts: the setupEditor form of main, with the tests of the lens in that form. - v1BindingSnapshotDiff.test.ts: the version of main. The change of the lens (the second version is an edit that keeps the block ID) is now in v1BindingSnapshotDiff.fixture.ts. - tests/src/unit/... (5 files): main moved them to tests/src/integration. The new markdownSyntaxText copy snapshots are at the new path. The toggle round-trip case of the lens is in htmlRoundTripCases. The two noCaption snapshots of main and of the lens are equal. - pnpm-lock.yaml, playground/src/examples.gen.tsx: the files of main, then made again by pnpm install and vp run gen. The text-lens example has no ariakit and shadcn dependencies now (the template of main).
…wser tests Main runs the tests of math-block in Node, and a test that needs a DOM is a browser test. The three test files of the lens commit 82b18c6 export and parse HTML. They are now X.browser.test.ts, without the jsdom docblock. The tests do not change. Three cases fail with the code of main (#3389): for a formula that KaTeX renders in part (x \badcommand y), main keeps the MathML of KaTeX, and these cases expect an merror element.
Main has the fix for a formula that does not compile (#3389) with its own browser tests. The three test files of the lens branch were for the older form of that fix, and three of their cases expect the older result. Without them, math-block is equal to main.
Summary
A math block whose formula does not compile makes the HTML export and the markdown export throw. Inline math with such a formula is not in the export. A user makes this state while typing, for example
\frac{1}{.KaTeX gives no
mathelement for such a formula, and the two export components then rendered nothing. For such a formula, they now render amathelement with the source as text and theapplication/x-texannotation. Thus the HTML parse gives the formula back, and the markdown export writes the source.Testing
main.main). No browser run was made locally.Notes
latexToMathMLElementis a public export of@blocknote/math-block. Its return type is now{ mathMLElement } | { error }. Thus TypeScript code outside this repository that readsmathMLElementwithout a check oferrordoes not compile. The alternative is to keep the old type and to make the check only in the two components.Summary by CodeRabbit