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

Preformatted block collapses new lines when pasting in text #27660

Closed
guarani opened this issue Dec 10, 2020 · 3 comments
Closed

Preformatted block collapses new lines when pasting in text #27660

guarani opened this issue Dec 10, 2020 · 3 comments
Assignees
Labels
[Block] Preformatted Affects the Preformatted Block - used for showing preformatted text [Block] Verse Affects the Verse block [Type] Bug An existing feature does not function as intended

Comments

@guarani
Copy link
Contributor

guarani commented Dec 10, 2020

Describe the bug

Text copied in from outside sources is often wrapped in (hidden) HTML tags. When pasting this content into Preformatted or Verse blocks, the hidden tags seem to cause the text to lose its new lines and get pasted as a single line.

To reproduce

  1. Copy a block of text from a lyrics site that contains hidden tags (on example is here)
  2. Create a Preformatted or Verse block
  3. Paste in the content
  4. Notice that new lines are lost and the content is all on a single line (especially noticeable when previewing)

For reference, this is the output I see in the browser console:

 <pre id="lyric-body-text" class="lyric-body wselect-cnt">
If I woke up without ya
I don't know what I would do
Thought I could be single forever 'til I met you
Usually don't be fallin', be fallin', fallin' first
You got a way of keeping me comin' back to back
I just found out the only reason that you lovin' me
Was to get back at your ex lover but before you leave
Usually I would never, would never even care
Baby, I know she creepin' I feel it in the air</pre>

Expected behavior
New lines in pasted content should be preserved

Screenshots

Editor version (please complete the following information):

  • WordPress version: master branch latest commit at time of writing e5b9df1
  • Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? gutenberg plugin
  • If the Gutenberg plugin is installed, which version is it? 9.5

Desktop (please complete the following information):

  • OS: macOS
  • Browser Firefox
  • Version 83.0
@guarani guarani added [Type] Bug An existing feature does not function as intended [Block] Verse Affects the Verse block [Block] Preformatted Affects the Preformatted Block - used for showing preformatted text labels Dec 10, 2020
@settenop
Copy link

The problem seems to be in this line:

let valueToInsert = create( { html: content } );

content (as returned from pasteHandler) is a string in which lines are separated by newlines, the newlines are lost when content is passed to the create function as html.

Passing content as text could fix the bug (let valueToInsert = create( { text: content } );) for this specific case but I suspect we need a way to pick the right parameter (text or html).

@kathrynwp
Copy link

Looks like there was a PR fixing this issue early in 2021. @draganescu could you please confirm that this issue can be closed? Thanks very much!

@draganescu
Copy link
Contributor

It's fixed to me! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Preformatted Affects the Preformatted Block - used for showing preformatted text [Block] Verse Affects the Verse block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants