-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix Quote to Paragraph transform #66953
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
base: trunk
Are you sure you want to change the base?
Conversation
… or at least one paragraph
3bf7120 to
918d463
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
|
Size Change: +39 B (0%) Total Size: 1.82 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 918d463. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11813860105
|
| return ( | ||
| ! RichText.isEmpty( citation ) || | ||
| block.innerBlocks.some( | ||
| ( { name } ) => name === 'core/paragraph' |
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 think this transform should still be possible. Unfortunately the meaning has changed from "convert to paragraph" to just unwrap the entire thing. If we change this, it will no longer be possible to unwrap the quote?
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.
See #51934
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 think this transform should still be possible.
Possibly. How should it work ... convert any non-paragraphs blocks to paragraphs? We can try running transforms to paragraphs for any inner block types that have that transform. The isMatch would have to check if there are available transforms for all inner block types, but it might not be too bad.
The other option is to allow it to simply unwrap, but I think it'd be weird if it's called a Paragraph transform, and yet it doesn't actually convert to paragraphs.
If we change this, it will no longer be possible to unwrap the quote?
There's still an 'Ungroup' option in the block settings menu that unwraps the quote. It's not surfaced in the transform menu. It seems to work for any inner block types that quote may have.
I only found it because it's mentioned in the e2e tests.
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.
The other option is to allow it to simply unwrap, but I think it'd be weird if it's called a Paragraph transform, and yet it doesn't actually convert to paragraphs.
This seems to be what @richtabor mentions in #51934 (comment)
That PR was merged, though I suspect this may be better suited — to have "Unquote" as an option, instead of "Paragraph".
If the ungroup transform supported a label of __( 'Unquote' ), that'd allow it to be shown more clearly in the block settings and transforms menus.
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.
For what it's worth, "unquote" makes logical sense to me as a permanent option.
I'm likening it to markdown.
To wrap content in a quote we add >
There are multiple entities inside this quote 😄
Removing the > will just 'unwrap' it, regardless of what the internal entities are.
ellatrix
left a comment
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.
Could we add an e2e test?
I can follow up with that once we have an idea of how we want it to work 👍 |
What?
Fixes something I randomly spotted. If you try transforming a quote block that contains no paragraphs or citations to a paragraph block, an error is thrown. It happens because
switchToBlockType(which handles transforms) requires the transformed blocks to contain one of the destination types (paragraph). The transform instead results in a heading block, soswitchToBlockTypereturnsnullandreplaceBlockschokes on that value.This also unearths another issue, in many places
switchToBlockTypeis called followed by a call toreplaceBlockswith the results ofswitchToBlockType. IfswitchToBlockTypereturnsnull, these errors can be thrown.In this PR I'm also adding some protection against calling
replaceBlockswithnull.Potentially
replaceBlockscould handle this, but I decided not to go that route. If this were typescript we wouldn't add safety toreplaceBlocksitself or weaken the parameter types by acceptingnull, instead it would fail to compile because the call sites try calling with the wrong type. As there may be TS consumers of this code, I decided to go with the more strongly typed approach and fix the call sites.How?
isMatchto the Quote -> Paragraph transform to ensure it only appears when a valid transform is possible.switchToBlockTypeTesting Instructions
Screenshots or screencast
Before
After