alleyinteractive / wp-block-converter

Convert HTML into Gutenberg Blocks with PHP
GNU General Public License v2.0
40 stars 2 forks source link

Nested images aren't properly sideloaded #26

Closed srtfisher closed 3 months ago

srtfisher commented 3 months ago

Description of the bug

Nested images are not properly being converted to Gutenberg image blocks. This includes images wrapped in a <figure> tag and/or a <a> tag.

Steps To Reproduce

  1. Convert the following HTML:
<figure class="wp-block-image size-large"><a href="https://alley.com/wp-content/uploads/2022/01/Screen-Shot-2022-01-19-at-2.51.37-PM.png"><img decoding="async" loading="lazy" width="786" height="672" src="https://alley.com/wp-content/uploads/2022/01/Screen-Shot-2022-01-19-at-2.51.37-PM.png?w=786" alt="" class="wp-image-5962"></a></figure>

OR even

<a href="https://alley.com/wp-content/uploads/2022/01/Screen-Shot-2022-01-19-at-2.51.37-PM.png"><img decoding="async" loading="lazy" width="786" height="672" src="https://alley.com/wp-content/uploads/2022/01/Screen-Shot-2022-01-19-at-2.51.37-PM.png?w=786" alt="" class="wp-image-5962"></a>
  1. Expect to get a Gutenberg block but instead get a HTML block:
    <!-- wp:html --><figure class="wp-block-image size-large"><a href="https://alley.com/wp-content/uploads/2022/01/Screen-Shot-2022-01-19-at-2.51.37-PM.png"><img decoding="async" loading="lazy" width="786" height="672" src="https://alley.com/wp-content/uploads/2022/01/Screen-Shot-2022-01-19-at-2.51.37-PM.png?w=786" alt="" class="wp-image-5962"></a></figure><!-- /wp:html -->

I would also expect that the image would be downloaded to the media library and it was not.

Additional Information

Even if the block won't be converted to a image block it should have the image downloaded to the media library and not reference an external file.