Gutenberg: Unable to copy/paste text without block boundary comments

Created on 15 Aug 2018  路  12Comments  路  Source: WordPress/gutenberg

Describe the bug
When writing content I hit enter for a new paragraph which creates a new paragraph block. However if I then want to copy/paste what I've written my clipboard contains the text PLUS the comment tags.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the editor and add a paragraph block
  2. Start typing and then hit enter (repeat for a few paragraphs)
  3. Select all the paragraphs and do CTRL-C
  4. CTRL-V into notepad

Expected behavior
Just copy my text please...

Screenshots
n/a

Desktop (please complete the following information):

  • OS: Linux Mint
  • Browser Chrome
  • Version 68.0.3440.106 (Official Build) (64-bit)
[Feature] Raw Handling [Type] Bug

Most helpful comment

Personally? I might be copying and pasting into Word for spell checks, for feedback (sharing in an email), for copying snippets into social media. There are loads of use cases that I'm sure others need for basic copy paste functionality.

All 12 comments

To be clear, when you copy text it includes the HTML comments used to denote a Gutenberg block, correct?

eg:

<!-- wp:paragraph -->
<p>My text.</p>
<!-- /wp:paragraph -->

right?

Correct

I tested with WordPress 4.9.8 and Gutenberg 3.5.0 and Firefox 61.0.2 on macOS 10.13.6 and confirmed that Gutenberg HTML block comments are copied into the clipboard when using the "Copy All Content" option in the More menu in the top toolbar or if I select multiple blocks at once but they are not included if I copy content from a single block.

My understanding is that this is by design to allow content to be copied from one post to another using the visual editor without losing block information.

@scottybo may I ask your use case and what your reasons are for wanting to leave the block boundary comments out of copied content and what you think about the balance on being able to copy and paste content as blocks within the Gutenberg editor versus elsewhere?

Personally? I might be copying and pasting into Word for spell checks, for feedback (sharing in an email), for copying snippets into social media. There are loads of use cases that I'm sure others need for basic copy paste functionality.

Noting that there is some intentionality to this, originally implemented in #1013 and #1331. The content of the paragraphs are markup, and a similar expectation exists that one can copy the content from one post to another editor session and preserve the same formatting.

This can tie in to some similar discussions about:

  • Does a paragraph block need the comment demarcations? For non-default-formatting, the answer is yes.
  • Gutenberg's avoidance of wpautop

Sounds like this is working as intended. If you had more than plain text content the HTML would preserve it, so this approach makes sense.

I can see the use case of wanting to copy only the text from the post, but that sounds like a new feature (a "copy as plain text" button). I don't think it fits into the common use-case for multi-block copy/paste and would be better-suited to a Gutenberg editor plugin.

I think a "Copy as plaintext" plugin would do the trick here but I don't see it as being part of the core Gutenberg experience, so I'm closing this one as a won't fix.

Reopening, as this appears to be a bug. CopyHandler sets both the text/plain and the text/html MIME types to be the serialised content, which is incorrect for text/plain (which should just be the text content), and correct-but-inaccurate for text/html (which doesn't need the block demarcations).

I'm inclined to have multiple data formats:

text/plain: Text content, all block demarcations and HTML stripped.
text/html: HTML content, with block demarcations comments stripped. This improves the behaviour of pasting block content into the Classic Editor, too.
application/vnd.wordpress.block+json: The unserialised JSON blob of blocks, which we can use when pasting into Gutenberg.

@iseulde: I could tell from #1013 why text/plain is set to include the HTML, can you confirm what's going on?

@pento Sounds good to me, as long as there is a way to copy the HTML content including HTML comments to some other application. I guess that is still possible by copying the contents of the code editor. Also, what should the copy all button do in your opinion? Should it depend on the editor you're in?

Other applications should be able to access the application/vnd.wordpress.block+json data, native clipboard APIs provide that functionality, and I assume browsers pass that data into the native clipboard correctly. We could add a application/vnd.wordpress.block+html type, too, which would contain the string the serialize() returns (the string that's currently put into text/plain and text/html), if native applications want the HTML-ified version, instead.

I think Copy All should have the same behaviour as if you press Cmd+A, Cmd+C. In the Visual Editor, that would be the same as above. In the Code Editor, it should put the HTML content (including HTML comments) into text/plain.

@pento @iseulde what is the status of this one? Also have to consider copying content to paste in the same editor to create a new block.

In the future, it might be nice to evolve the "Copy All" to be a flyout "Export" menu including options for copying with all attributes, copying just the visual render, and even downloading an HTML version.

There's also the option of opening "preview" and copying from there (which doesn't include comments).

I'm inclined to have multiple data formats:

text/plain: Text content, all block demarcations and HTML stripped.
text/html: HTML content, with block demarcations comments stripped. This improves the behaviour of pasting block content into the Classic Editor, too.
application/vnd.wordpress.block+json: The unserialised JSON blob of blocks, which we can use when pasting into Gutenberg.

This is pretty much what I had in mind, at least when using the native Copy action. (I don't think expecting third-party apps to look at application/vnd.wordpress.block+json is realistic yet, but at least the format is there for Gutenberg itself and, perhaps in the future, any specialised processing tool that looks for it.) I'm undecided on whether the Copy All Content button should follow this behavior, or whether it should still copy the boundaries onto the text/* formats.

I might be copying and pasting into Word for spell checks

This is also a usage case for me. Would be glad if this feature was implemented.

Was this page helpful?
0 / 5 - 0 ratings