Repository navigation
Paste: Don't convert LaTeX to a Math block when it can't be inserted - #84059
snehapatil2001 wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
🤖 PR meta 🤖🎉 PropsUnlinked AccountsThe 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. 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 🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
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.pasteHandlerconverts plain text that looks like LaTeX into acore/mathblock 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 optionalconvertLatexToMathoption, which defaults totrue, so existing callers are unaffected. It also checks thatcore/mathis registered before converting.@wordpress/block-editor(rich-text/event-listeners/paste-handler.jsandwriting-flow/use-clipboard-handler.js) passcanInsertBlockType( 'core/math', rootClientId ). This keeps@wordpress/blocksfree of editor-store knowledge. It also covers parents that don't allow the Math block, not just the Preferences toggle.packages/blocks/README.mdfor 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
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}npm run test:unit -- packages/blocks/src/api/raw-handling.Testing Instructions for Keyboard
Screenshots
Screen.Recording.2026-10-05.at.2.34.55.AM.mov
Screen.Recording.2026-10-05.at.3.28.21.AM.mov