-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add block transforms between Verse and Quote blocks #73068
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
Conversation
Enables bidirectional transformations between Verse, Quote, and Pullquote blocks, allowing users to convert content between these semantically related block types. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @deborah86. 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. |
|
Size Change: +137 B (+0.01%) Total Size: 2.58 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 0601424. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20291224986
|
|
@annezazu, we have decided to deprecate the Pullquote block. However, because this may have an impact on users and default themes, we will ship this in the 7.0 release. To be cautious, we plan to merge #72028 after 6.9 RC1 is released. Once this is merged, the transformation to the Pullquote block itself will no longer be necessary. For discussions regarding the deprecation of the Pullquote block, please refer to #/. |
Remove transforms between Verse and Pullquote blocks as Pullquote is being deprecated in WordPress 7.0. This addresses feedback to avoid adding new functionality to a block scheduled for removal. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Ah ha. Thank you so much for commenting to connect those dots. I updated the PR to remove the transforms for the pullquote. Here's what we have now: verse.transforms.mov |
| .map( ( { attributes } ) => attributes.content || '' ) | ||
| .filter( Boolean ) | ||
| .join( '<br>' ); | ||
| return createBlock( 'core/verse', { content } ); |
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.
What do we expect when there's other content in the quote block such as headings, images, lists, etc.?
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.
Hmm. Maybe we only show a transform to verse when there are paragraph or heading blocks, similar to only showing a transform to a button when the paragraph is fully linked. Right now, if you convert heading and paragraph, I think it does what I'd expect: keeps the text but changes to verse. However, it causes you to lose images, lists, etc so we can target just heading and paragraph. I'll explore that.
converting.mov
|
Alright! I've updated the PR to only show a transform from Quote to Verse if the Quote only includes Heading and Paragraph blocks. If a Quote block contains more, then it won't show as a transform to Verse. When converting Heading and Paragraph to Verse, I think it makes sense that you'd keep the content but lose the heading. Here's what it looks like now: update.to.only.work.with.p.h.mov |
| isMatch: ( {}, block ) => { | ||
| return block.innerBlocks.every( | ||
| ( { name } ) => | ||
| name === 'core/paragraph' || name === 'core/heading' |
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 suppose we're fine with losing the extra formatting from headings when transforming from quote to verse. I wonder why we're not doing the same with lists then? Should we support lists the same way we support heading and paragraph (one list item per line, essentially)?
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.
What if we only allow it for paragraphs?
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'd be mostly fine with that, although I'm assuming the goal here is to lose as little content as possible during the transformation.
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 just added more to this PR to allow it for headings, lists, other verse blocks, and paragraph. I think this is fine as it keeps the content. If we want to just have it for paragraph to start, I'm also okay with that as an initial iteration. LMK what you all think and I'll update the PR accordingly. I personally like that it's available for more blocks within the Quote block.
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.
Ok if you want as many as possible, I would suggest a different strategy: convert all blocks in the array to paragraphs first. Then just use the content in all those paragraphs which would be pretty simple. In the isMatch function you could check if there's a paragraph transform available for every block in the array.
I think this method would work better, you will be able to avoid having to manually add handling for every type of block.
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 current isMatch logic only becomes true if all inner blocks can be transformed into Paragraph blocks. In other words, if there is even one Group block that cannot be transformed to a Paragraph block, the Quote block cannot be transformed to a Verse block:
Perhaps the ideal logic would be to check whether the Quote block contains any blocks that can be transformed to a Paragraph block?
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 am okay with this limitation as it avoids content lost. For example, if you have content within the group block of some kind that can't be transformed, it'll be lost if we proceed with a transformation.
- Add support for core/list and core/verse blocks in Quote → Verse transform - Add recursive helper function to extract content from nested list items - Remove duplicate Quote → Verse transform from verse block (now handled in quote block) - List content is flattened and joined with line breaks when converting to verse 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Please note that we have deprecated the Pullquote block. See #11610 for more details. |
The Quote to Verse transform was failing for paragraph blocks because switchToBlockType() returns null when converting a paragraph to a paragraph (no conversion needed). Updated isMatch and transform functions to handle paragraphs directly, while still using switchToBlockType for other block types (headings, lists, etc.) that need conversion. This ensures the transform works with: - Paragraphs (now fixed) - Headings - Lists - Any block that can convert to a paragraph 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
It should be good to go now. I've addressed the issues and implemented the suggested approach. Of note, I fixed a bug in the isMatch logic where the Quote to Verse transform wasn't appearing for paragraph blocks. The issue was that switchToBlockType(paragraphBlock, 'core/paragraph') returns null when the block is already a paragraph since no conversion is needed. The solution was to update both isMatch and transform functions to handle paragraphs directly since they're already in the target format, while using switchToBlockType() for other block types like headings and lists. This implements the suggestion to convert all blocks in the array to paragraphs first. @ellatrix curious what you make of this approach :) I've tested locally and confirmed that the transform now works correctly with Quote blocks containing paragraphs, headings, lists, mixed content, or any block that supports paragraph conversion. testing.v.to.q.mov |
|
@annezazu I've fixed the code conflict for retesting. |
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
|
Approach looks great! Should we add a small e2e test, maybe just some mixed content to transform to verse? |
Tests that a Quote block containing mixed content (paragraph and heading) can be successfully transformed to a Verse block with content preserved and joined with <br> tags. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Thank you all for the help here. Added in an e2e test as suggested that tests transforming a Quote block with mixed content (paragraph and heading block) to Verse. |
|
It looks almost good, but I think we may need to address this feedback: #73068 (comment) |
|
Responded there. I personally think we can proceed without it as I don't think we should have it be too open for a transformation from Quote to Verse. |
t-hamano
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.
I see, let's adjust the logic in a follow-up if necessary 👍
What?
Closes #30775
Adds bidirectional block transforms between Verse and Quote blocks. Pullquote not considered since the plan is to deprecate and, for the quote block, the transform is only visible if the quote includes heading and paragraph blocks to prevent content loss.
Why?
Users need the ability to convert between these semantically related text blocks without losing content. Previously, there was no way to transform a Verse block into a Quote.
How?
Added transforms to the
verseandquoteblocktransforms.jsfiles following the same pattern as other similar PRs. Each block can now transform to and from the other two blocks, mapping content attributes appropriately.Testing Instructions
Testing Instructions for Keyboard