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

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 <dhananjaykuber@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: scruffian <scruffian@git.wordpress.org>

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
@carolinan carolinan added [Block] Paragraph Affects the Paragraph Block [Feature] Block Transforms Block transforms from one block to another [Type] Enhancement A suggestion for improvement. labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Paragraph Affects the Paragraph Block [Feature] Block Transforms Block transforms from one block to another [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Paragraph with Image: Transform to image
2 participants