Skip to content

Paste: Don't convert LaTeX to a Math block when it can't be inserted - #84059

Open
snehapatil2001 wants to merge 2 commits into
WordPress:trunkfrom
snehapatil2001:fix/84054
Open

snehapatil2001 wants to merge 2 commits into
WordPress:trunkfrom
snehapatil2001:fix/84054

Conversation

@snehapatil2001

Copy link
Copy Markdown
Contributor

What?

Closes #84054

Stops pasted LaTeX from being converted into a Math block when the Math block can't be inserted, so the text is pasted normally instead of being silently dropped.

Why?

When a user disables the Math block (Preferences → Blocks → Manage block visibility), pasting a formula like x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} into a paragraph pastes nothing.

pasteHandler converts plain text that looks like LaTeX into a core/math block without checking whether that block is allowed. Disabling a block in Preferences doesn't unregister it. It only removes it from the allowed block types, so the editor then refuses to insert the generated block and the paste is lost.

How?

  • pasteHandler (@wordpress/blocks) gets a new optional convertLatexToMath option, which defaults to true, so existing callers are unaffected. It also checks that core/math is registered before converting.
  • The two paste call sites in @wordpress/block-editor (rich-text/event-listeners/paste-handler.js and writing-flow/use-clipboard-handler.js) pass canInsertBlockType( 'core/math', rootClientId ). This keeps @wordpress/blocks free of editor-store knowledge. It also covers parents that don't allow the Math block, not just the Preferences toggle.
  • When conversion is skipped, the text falls through to the normal plain-text/markdown path.
  • Added a unit test, a changelog entry, and the regenerated packages/blocks/README.md for the new option.

This doesn't cover the other points raised in the issue: pasting a formula into a list as inline math, or a setting to turn off auto-conversion while Math stays enabled. Copying from a source that puts <pre>/styled HTML on the clipboard (for example VS Code) still produces a Code block, as before.

Testing Instructions

  1. Open a post and insert a paragraph.
  2. Copy this formula from a plain-text source (not a code editor): x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
  3. Paste it into an empty paragraph. A Math block is created.
  4. Undo, then open Options → Preferences → Blocks, and uncheck Math.
  5. Paste the formula into an empty paragraph again. It is pasted as plain text in the paragraph.
  6. Re-check Math and confirm step 3 works again.
  7. Run npm run test:unit -- packages/blocks/src/api/raw-handling.

Testing Instructions for Keyboard

  1. Use Tab to move focus into the paragraph, then paste with Cmd/Ctrl+V.
  2. Open Preferences with Shift+Alt+Cmd/Ctrl+P (or Options menu → Preferences), then Tab to the Blocks tab and toggle the Math checkbox with Space.
  3. Confirm the same results as above.

Screenshots

Before After
Screen.Recording.2026-10-05.at.2.34.55.AM.mov
Screen.Recording.2026-10-05.at.3.28.21.AM.mov

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added [Package] Blocks /packages/blocks [Package] Block editor /packages/block-editor labels Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @k79e.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: k79e.

Co-authored-by: snehapatil2001 <snehapatil02@git.wordpress.org>
Co-authored-by: BlackStar1991 <blackstar1991@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

This branch has not been deployed

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

Labels

[Package] Block editor /packages/block-editor [Package] Blocks /packages/blocks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't paste the math formula after disabled math block

1 participant