Skip to content

[lexical] Fix: preserve block equations ($$) in MarkdownShortcutPlugin#8223

Draft
Jynx2004 wants to merge 19 commits intofacebook:mainfrom
Jynx2004:new_fix
Draft

[lexical] Fix: preserve block equations ($$) in MarkdownShortcutPlugin#8223
Jynx2004 wants to merge 19 commits intofacebook:mainfrom
Jynx2004:new_fix

Conversation

@Jynx2004
Copy link
Contributor

@Jynx2004 Jynx2004 commented Mar 14, 2026

Description

Block math equations ($$...$$) created via the toolbar were incorrectly converted to inline equations ($...$) when toggling markdown mode via the MarkdownShortcutPlugin.

Root cause: The EQUATION transformer's export function always returned $${equation}$ (inline syntax) regardless of whether the node was a block or inline equation. There was also no transformer to import/match $$...$$ patterns.

Closes #6936

Test plan

Created a new test for testing this functionality .

Before

inserting a block equation and clicking the Markdown button converted $$x^2 + y^2 = z^2$$ → $x^2 + y^2 = z^2$ (inline)

After

block equations are preserved as $$x^2 + y^2 = z^2$$ when toggling markdown mode

@vercel
Copy link

vercel bot commented Mar 14, 2026

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Mar 15, 2026 5:41pm
lexical-playground Ready Ready Preview, Comment Mar 15, 2026 5:41pm

Request Review

@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 Mar 14, 2026
Copy link
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.

This only handles export, not import, so it's not complete.

@etrepum
Copy link
Collaborator

etrepum commented Mar 14, 2026

See also #8194 which is probably a more complete fix but is not yet acceptable because there are no tests.

@Jynx2004
Copy link
Contributor Author

Jynx2004 commented Mar 14, 2026

This only handles export, not import, so it's not complete.

I think having a single import for both inline as well as block case will also work fine as both have the same trigger $

@etrepum
Copy link
Collaborator

etrepum commented Mar 14, 2026

It could possibly be implemented in one transformer or two, but either way this PR is not complete because it doesn’t have test coverage to show that import works. When you write those tests you’ll see that it probably doesn’t work as-is.

@Jynx2004
Copy link
Contributor Author

Jynx2004 commented Mar 14, 2026

It could possibly be implemented in one transformer or two, but either way this PR is not complete because it doesn’t have test coverage to show that import works. When you write those tests you’ll see that it probably doesn’t work as-is.

Made some changes in the unit test to check the import works for both the cases .

Jynx2004 and others added 2 commits March 15, 2026 10:27
Co-authored-by: Bob Ippolito <bob@redivi.com>
Copy link
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.

What's needed to demonstrate that this PR is complete are tests to ensure that the exported markdown can be imported and the result is an EquationNode with the right setting for inline and the correct contents.

@Jynx2004 Jynx2004 marked this pull request as draft March 16, 2026 17:29
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.

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

2 participants