Skip to content
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

Paragraph with Image: Transform to image #68796

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

dhananjaykuber
Copy link
Contributor

Fixes #56344

What?

This PR adds the ability to transform a paragraph block containing only an inline image into a proper image block, preserving all image attributes and alignment settings.

Why?

Users sometimes end up with inline images inside paragraph blocks with no straightforward way to convert them into proper image blocks. This creates a suboptimal editing experience, especially when users want to take advantage of image block-specific features.

How?

Added a new block transform to the paragraph block that:

  1. Detects when a paragraph contains exactly one inline image with no other content
  2. Preserves all image attributes (src, alt, title, dimensions, class)
  3. Maintains existing alignment settings
  4. Handles linked images by preserving link destination and URL
  5. Shows the transform option in the block toolbar when appropriate

Testing Instructions

  1. Open the block editor
  2. Create a new paragraph block
  3. Insert an inline image into the paragraph
  4. Delete any text in the paragraph so only the image remains
  5. Click the block toolbar's transform button (three dots)
  6. Verify that "Transform to Image block" appears as an option
  7. Click the transform option and verify that:
    The image appears correctly in its new block
    a. All image attributes are preserved
    b. Alignment settings remain intact
    c. If the image was linked, the link is maintained

Screenshots or screencast

screen-capture.1.webm

Screenshot 2025-01-21 at 10 38 55 AM

Copy link

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core, Gutenberg Plugin.
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Copy link

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 props-bot label.

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

Co-authored-by: dhananjaykuber <[email protected]>
Co-authored-by: carolinan <[email protected]>
Co-authored-by: scruffian <[email protected]>

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

@dhananjaykuber dhananjaykuber changed the title feart: Add image block transformation for inline image in paragraph b… Paragraph with Image: Transform to image Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Paragraph with Image: Transform to image
1 participant