Skip to content

Fix: Verse Block Preserves Text Formatting (italic, bold, etc.) on Paste#69544

Open
dhruvikpatel18 wants to merge 1 commit intoWordPress:trunkfrom
dhruvikpatel18:fix/57624-verse-block-preserve-text-formatting
Open

Fix: Verse Block Preserves Text Formatting (italic, bold, etc.) on Paste#69544
dhruvikpatel18 wants to merge 1 commit intoWordPress:trunkfrom
dhruvikpatel18:fix/57624-verse-block-preserve-text-formatting

Conversation

@dhruvikpatel18
Copy link
Copy Markdown
Contributor

Closes #57624

What?

This PR fixes an issue where text formatting (italic, bold, etc.) is stripped when pasting content into the Verse block.

Why?

When pasting formatted verse (poetry) into the Verse block, whitespace is preserved but all text formatting is stripped out. This creates unnecessary work for content editors who then need to manually re-add all formatting.

The Paragraph block correctly retains text formatting on paste, and the Verse block should behave similarly since verse content (poetry, lyrics, etc.) often uses italics, bolds, and similar formatting.

Testing Instructions

  1. Create a post and insert an empty Verse block
  2. Find a poem that includes italics, for example: https://www.poetryfoundation.org/poems/161828/luh-friends
  3. Copy the poem's text and paste it into the empty Verse block
  4. Verify that the italics are preserved (before this fix, they would be removed)

Testing Instructions for Keyboard

Screenshots or screencast

Before

before_verse.mov

After

after_verse.mov

@dhruvikpatel18 dhruvikpatel18 marked this pull request as ready for review March 12, 2025 12:18
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 12, 2025

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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @jmccall75.

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.

Unlinked contributors: jmccall75.

Co-authored-by: dhruvikpatel18 <dhruvik18@git.wordpress.org>
Co-authored-by: hbhalodia <hbhalodia@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: Saoming <samuel1337@git.wordpress.org>

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

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Feature] Paste [Block] Verse Affects the Verse block labels Mar 12, 2025
Copy link
Copy Markdown
Contributor

@hbhalodia hbhalodia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentionally added to fix another issue in #27781 / #27660. Let's ensure we're not introducing a regression.

@Mamaduka
Copy link
Copy Markdown
Member

Hi, @dhruvikpatel18

Did you get a chance to investigate this further?

@dhruvikpatel18
Copy link
Copy Markdown
Contributor Author

Hi @Mamaduka

The trade-off with the __unstablePastePlainText property is that it was implemented to preserve multiline formatting when pasting content like verses. When enabled, it successfully maintains line breaks because newline characters (\n) are naturally part of plain text.

However, this approach has a significant limitation. By using plain text mode, we sacrifice rich text formatting such as bold and italics, since these formatting elements only exist in the HTML version of the pasted content.
Essentially, we have two options:

  1. Enable __unstablePastePlainText: This preserves line breaks but strips all rich text formatting (bold, italics)
  2. Disable __unstablePastePlainText: This maintains rich text formatting but may handle line breaks differently as they would be processed through HTML

The current implementation forces us to choose between preserving multiline structure OR preserving rich text formatting - we can't have both simultaneously with the current code structure.

if ( pastePlainText ) {
onChange( insert( value, create( { text: plainText } ) ) );
return;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Verse Affects the Verse block [Feature] Paste [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verse Block: Do Not Strip Text Formatting (italic, bold, etc.)

3 participants