WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.5k stars 4.19k forks source link

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

Open jmccall75 opened 10 months ago

jmccall75 commented 10 months ago

Description

When pasting formatted verse (poetry) into the Verse block, the white space is preserved. That's awesome, and a big step toward making it easier for publishers and writers to accurately present poetry online.

However, all text formatting is stripped out when pasting into the verse block, in particular italics and bolds. This doesn't seem to be a technical hurdle, since the paragraph block retains text formatting.

This issue occurs when copying from various sources. I personally tried HTML pages in the browser, Google Docs, .docx, and .rtf.

I assume this must be either an oversight or a choice. I'm guessing oversight, since the Verse block seems to be mostly a port of the Code and Preformat blocks, where removing text formatting make more sense.

But verse (poetry, lyrics, etc.) often use italics, bolds, and similar formatting. Not allowing that to be pasted in creates unnecessary work for content editors, who then must carefully re-add all that formatting.

It also creates confusion and frustration, since it's obvious enough that the paragraph block doesn't strip out these formats.

Step-by-step reproduction 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. The italics have been removed.
  5. Now repeat the above but with a Paragraph block. The italics remain, but of course the whitespace is no longer preserved.

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 6.4.2, custom theme, Windows. Tested in Chrome and Firefox. Not using the Gutenberg plugin, just the core block. (Does that mean this bug report should be moved to another repository?)

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Saoming commented 10 months ago

I tested it. I have found the problem.

I think essentially it has to be related to __unstablePastePlainText

If you take a look at these:

https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/verse/edit.js

https://github.com/WordPress/gutenberg/blob/cd1237e82423ff32c25bc7c88f874a75d876abf1/packages/block-editor/src/components/rich-text/index.native.js#L76

I think we should either remove using unStablePastePlainText and maybe add another event to check whether the HTML there the text its wrapped has strong or em