Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical-playground] [markdown] fix: block equations falsely converted to inline in markdown conversion #7214

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

nmzabith
Copy link

@nmzabith nmzabith commented Feb 20, 2025

Description

This pull request includes changes to improve the handling of inline and block equations in the EquationNode and MarkdownTransformers classes. The most important changes include adding a method to determine if an equation is inline and modifying the regex patterns to better handle both inline and block equations.

Improvements to equation handling:

Closes #6936

Test plan

  1. add the below markdown content through MarkdownShortcutPlugin
  2. Press the Markdown button
  3. Press the Markdown button (Block equations wont converted to inline)

Other way to test

  1. Enter an equation, e.g. "x^2 + y^2 = z^2" via the toolbar (Insert -> Insert Equation) and uncheck "inline".
  2. Press the Markdown button
  3. Press the Markdown button (Block equations wont converted to inline)
# KaTeX Equations in Markdown

## Inline Equations

You can write inline equations like this: $E = mc^2$ or $a^2 + b^2 = c^2$.

A more complex inline equation example:

\( \sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6} \)

## Block Equations

Block equations are useful for displaying more complex mathematical expressions. You can use them by wrapping in `$$`.

### Example 1: Quadratic Formula

$$ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$

### Example 2: Fourier Transform

$$ F(k) = \int_{-\infty}^{\infty} f(x) e^{-2\pi i k x} \,dx $$

### Example 3: Einstein Field Equations

$$ R_{\mu\nu} - \frac{1}{2} R g_{\mu\nu} + \Lambda g_{\mu\nu} = \frac{8\pi G}{c^4} T_{\mu\nu} $$

### Example 4: Probability Distribution (Gaussian Function)

$$ P(x) = \frac{1}{\sigma \sqrt{2\pi}} e^{-\frac{(x - \mu)^2}{2\sigma^2}} $$

### Example 5: Summation and Product Notation

$$ \sum_{i=1}^{n} i = \frac{n(n+1)}{2} $$

$$ \prod_{k=1}^{n} k = n! $$

## Conclusion

KaTeX makes it easy to include both simple and complex equations in Markdown. Whether using inline math \( x^2 + y^2 = z^2 \) or block equations, it's a powerful tool for documentation and note-taking.

Before

image

After

image

Copy link

vercel bot commented Feb 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 21, 2025 4:26pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 21, 2025 4:26pm

@facebook-github-bot facebook-github-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 Feb 20, 2025
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.

It would be great to add some tests to this PR to confirm that it works as expected. There's a deleteCharacter merges children from adjacent blocks even if the previous leaf is an inline decorator regression test that uses the equation node, you could use that as a starting point. There are also some unit tests for LexicalMarkdown.

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