Add embed-specific class to pasted embedded content
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
- Create a new page.
- Add a new YouTube block (or embed of your choice). Enter the URL of the embed into that block.
- Create a new content block below the YouTube block.
- Paste the embed's URL into that new content block. Note that the block is now previewing the embedded URL.
- Publish the page.
- View the page.
- Inspect the
iframein the first block. Note that the class is specific to the type of embed; i.e.wp-block-embed-youtube. - Inspect the
iframein 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.
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.