-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Pass correct content argument to enter transforms #54108
Conversation
Size Change: +2 B (0%) Total Size: 1.51 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this would be a breaking change. The code has been in the core for years now.
Maybe we should update the documentation; note that callback receives an attributes
-like object, plus keep the heading transformation fix.
Cc-ing @ellatrix and @ntsekouras as they are more familiar with the code in question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @jsnajdr ✅
This fixed the bug, and no breaking changes. The docs update also good to me.
Fixed a bug that I found when testing the Table of Contents block (namely its refactoring in #54094). Steps to reproduce:
/h2
Enter in the slash inserter to create a new Heading block.This happens because the Heading block's
enter
transform creates thecore/heading
block with an incorrectcontent
attribute. It should be a string, but instead it's an object,{ content: 'foo' }
.The fix is to:
transform
function with acontent
argument that is a string, not with anattributes
argument that is a{ content: string }
object. That's how theenter
transform is documented, and also how the similarprefix
transform is documented and implemented.content
parameter when creating thecore/heading
block. The/h2
value is not interesting and we don't want it to become the heading's text. Similar transforms forcore/code
andcore/separator
also ignore thecontent
parameter.There might be backward compatibility issues with this fix. If a plugin registers an
enter
transform that uses thecontent
parameter, and assumes it to be anattributes
-like object, it will stop working. Maybe, for compatibility, we should create a special class that acts both as a string and as an object with a.content
attribute:Then both
transform( content ) {}
andtransform( { content } ) {}
is possible.