gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Add embed-specific class to pasted embedded content

Open thatdevgirl opened this issue 8 years ago • 1 comments

Issue Overview

When adding embedded content via a specific embed block, the HTML for that embed includes a class that is specific to the type of embed. For example, if I embed a YouTube block, I see the following HTML code:

<figure class="wp-block-embed-youtube">
  [YOUTUBE VIDEO URL]
</figure>

I simply paste an embeddable piece of content into the editor, a new block is created with that embed. However, the class used in the HTML for that new block is generic:

<figure class="wp-block-embed">
  [YOUTUBE VIDEO URL]
</figure>

I would like to propose an enhancement for Gutenberg to figure out what embedded content is being pasted in (i.e. by domain name) and create the new embed block with the appropriate embed-specific class.

Steps to Reproduce

  1. Create a new page.
  2. Add a new YouTube block (or embed of your choice). Enter the URL of the embed into that block.
  3. Create a new content block below the YouTube block.
  4. Paste the embed's URL into that new content block. Note that the block is now previewing the embedded URL.
  5. Publish the page.
  6. View the page.
  7. Inspect the iframe in the first block. Note that the class is specific to the type of embed; i.e. wp-block-embed-youtube.
  8. Inspect the iframe in the second block. note that the class is generic; i.e. wp-block-embed.

Rationale

Using YouTube as an example: There are two ways of embedding a YouTube video: paste the video's URL or create a new YouTube embed block. Each way produces slightly different code, the difference being in the class. It would be best if the code was consistent, regardless of how a video is embedded on the page, especially from the theming perspective, if a theme developer is relying on the embed-specific classes for styling purposes.

Possible Solution

When an embed URL is pasted into the editor, something is being triggered to create a new block just for this embed. That function could also include a regex to look at the URL, match it to the set of supported embeddable content, and create the new block with the appropriate, embed-specific class.

thatdevgirl avatar Mar 27 '18 17:03 thatdevgirl

Let's put this as an idea for iterating after version one. I am putting this in the ideas project so that we don't forget it as it could be useful as an extra magic later on.

karmatosed avatar Apr 27 '18 19:04 karmatosed