Skip to content

[lexical-playground] Bug Fix: Add BLOCK_EQUATION markdown transformer for $$...$$ syntax#8435

Draft
matingathani wants to merge 5 commits into
facebook:mainfrom
matingathani:fix/block-equation-markdown
Draft

[lexical-playground] Bug Fix: Add BLOCK_EQUATION markdown transformer for $$...$$ syntax#8435
matingathani wants to merge 5 commits into
facebook:mainfrom
matingathani:fix/block-equation-markdown

Conversation

@matingathani
Copy link
Copy Markdown

Description

Currently, the EQUATION markdown transformer only handles inline equations ($...$). When a block equation using $$...$$ syntax is provided, the existing transformer falsely converts it to an inline equation.

This PR adds a BLOCK_EQUATION transformer that:

  • Exports block equations as $$...$$
  • Imports $$...$$ as a block equation node (inline: false)
  • Runs before the inline EQUATION transformer to prevent false conversion

Closes #6936

Test plan

Before

Typing $$x=1$$ in the playground with markdown shortcuts enabled converts it to an inline equation.

After

Typing $$x=1$$ correctly converts to a block (display) equation. Inline $...$ equations continue to work as before.

Copilot AI review requested due to automatic review settings May 1, 2026 01:19
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 1, 2026
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

Missing tests

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds proper Markdown import/export support for display (block) equations in the Lexical playground, preventing block equations from being treated as inline equations.

Changes:

  • Update inline EQUATION transformer export logic to only export inline equation nodes.
  • Add a new BLOCK_EQUATION text-match transformer to import/export $$...$$ as a non-inline EquationNode.
  • Register BLOCK_EQUATION before EQUATION in PLAYGROUND_TRANSFORMERS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment May 4, 2026 10:24pm
lexical-playground Ready Ready Preview, Comment May 4, 2026 10:24pm

Request Review

@matingathani matingathani requested a review from etrepum May 1, 2026 02:16
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label May 1, 2026
@etrepum etrepum changed the title [lexical-playground] Bug Fix: Add BLOCK_EQUATION markdown transformer for 5972...5972 syntax [lexical-playground] Bug Fix: Add BLOCK_EQUATION markdown transformer for $$...$$ syntax May 1, 2026
*/
import {CodeExtension} from '@lexical/code-core';
import {buildEditorFromExtensions} from '@lexical/extension';
import {createHeadlessEditor} from '@lexical/headless';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The tests shouldn't be using createHeadlessEditor, this is a modernized suite using buildEditorFromExtensions - all the new tests in here should be using that method to construct an editor and register the shortcuts extension as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This feedback hasn't been addressed yet

});

test('$convertFromMarkdownString imports $$...$$ as code format (block) when BLOCK_FORMAT precedes INLINE_FORMAT', () => {
const editor = createHeadlessEditor({
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

switch to buildEditorFromExtensions

});

test('$convertFromMarkdownString imports $...$ as bold format (inline) when BLOCK_FORMAT fails', () => {
const editor = createHeadlessEditor({
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

switch to buildEditorFromExtensions

@matingathani matingathani force-pushed the fix/block-equation-markdown branch from d834f54 to 980f42d Compare May 2, 2026 00:45
@matingathani
Copy link
Copy Markdown
Author

Tests were added after the initial review in a follow-up commit (the original first push was without tests). The branch has now been rebased on main.

Three unit tests are now in MarkdownTransformers.test.ts inside a describe('BLOCK_EQUATION') block:

  1. Inline fallback when block match fails$...$ typed at beginning of line does not match $$...$$ pattern; falls through to the inline transformer (bold format in the test fixture). Verifies no false-positive block equation detection.
  2. $convertFromMarkdownString with $$...$$ — imports correctly as code/block format when BLOCK_EQUATION transformer precedes the inline transformer in the array.
  3. $convertFromMarkdownString with $...$ — single-dollar syntax falls through to the inline transformer when the block pattern doesn't match.

Happy to add more cases if there are specific edge cases you want covered.

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented May 4, 2026

Still waiting for feedback to be addressed

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Block math equation is falsely converted to inline equation on MarkdownShortcutPlugin

3 participants