How to Copy WordPress Gutenberg Blocks in Plain Text

The Gutenberg Editor doesn’t support copying all the content in plain text as it was the case with the Classic editor. Instead, the HTML markup is included whenever multiple blocks are pasted in a plain text editor like Notepad.

The only exception to this rule is when copying individual blocks. In that case, the HTML tags are not included. It’s however not practical to copy multiple blocks individually.

According to a GitHub issue related to this behaviour, the logic behind this is to allow copying content between posts without losing the block information.

This makes perfect sense for those that primarily use the block editor for authoring their posts, however it’s quite counterintuitive to those that edit their posts with the help of external editors that don’t render the HTML.

Ideally, it would be preferable if users could set a default copying behaviour between the HTML or the plain text copier. This way, all users get access to the best of both worlds and can switch seamlessly whenever the need for either arises.

While we wait for some kind of compromise in that direction, here are some few workarounds that you can use to copy the blocks in plain text only.

Advertisements

1. Use a Temporary Classic Block

The classic block works just like the classic editor. What this means is that you can make use of the block temporarily to make a plain text copy while still using the Gutenberg Editor. To do this:

  1. Create a classic block at the bottom of the post.
  2. Copy all the paragraphs or the blocks you need copying.
  3. Paste the content in the classic block.
  4. Copy the content in the classic block to your plain text editor.
  5. Delete the classic block.
Advertisements

2. Use a Word Processor

Unlike plain or rich text editors, Word Processors like Microsoft Word and Google Docs, support rendering HTML.

As such, when you paste content into them from Gutenberg, all the copied content, not just the text, will be formatted as it was in the editor. However, copying content from the Word Processor to a plain text editor will not carry over its underlying markup.

We can therefore use this as a way to convert the HTML copy into plain text as follows:

  1. Copy the content from the Gutenberg Editor.
  2. Paste it into Word, LibreOffice Writer or Google Docs.
  3. Copy the content from the Word Processor to your Plain Text Editor.

I’ve only tested those three processors, however I expect others to work just the same.

Advertisements

3. Use Find and Replace Regular Expression

If you use a text editor that supports RegEx such as Notepad++ or Sublime Text, you can quickly strip way all the Gutenberg HTML tags using an expression as follows:

  1. Copy and paste the blocks into the text editor.
  2. Put the cursor at the very beginning.
  3. Open the Find and Replace window or panel.
  4. Enable searching Regular Expressions.
  5. Enter the RegEx <[^>]+> in the Find what box and leave the Replace with box empty.
    A screenshot showing the Fidn and repalce window of Notepad++
  6. Replace all the matches.
  7. Advertisements

The HTML tags and everything inside them will be removed leaving the text content only.

Advertisements

Strip Away HTML using an Online Service

There are plenty of online tools such as wtools and StripHTML that can help you remove tags from any HTML code.

Just copy the blocks and paste the code into one of the tools and strip the tags. You can then copy the bare text to your plain text editor.

Tags:

Author

Kelvin Muriuki is a web content developer that's passionate about keeping the internet a useful place. He is the founder and editor of Journey Bytes, a tech blog and web design agency. Feel free to connect with him regarding the content appearing on this page or on web and content development.

Leave a Reply

Feel free to share your comments or questions with me. I may not be able to respond immediately so please check later once I've approved your comment.

Your email address will not be published. Required fields are marked *