Skip to content

Commit

Permalink
Fixed multiple image handling bug.
Browse files Browse the repository at this point in the history
The url of the first image was used in all the other images, html copy past operations, and when using covert to blocks option.
  • Loading branch information
jorgefilipecosta committed Feb 2, 2018
1 parent daad3f2 commit 773f27c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions blocks/api/raw-handling/test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const types = [
'google-docs',
'ms-word',
'ms-word-online',
'one-image',
'two-images',
];

describe( 'raw handling: integration', () => {
Expand Down
1 change: 1 addition & 0 deletions blocks/api/raw-handling/test/integration/one-image-in.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<img class="alignnone wp-image-5114 size-medium" src="http://localhost/wp-content/uploads/2018/01/Dec-08-2017-15-12-24-17-300x137.gif" alt="" width="300" height="137" />
3 changes: 3 additions & 0 deletions blocks/api/raw-handling/test/integration/one-image-out.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:image -->
<figure class="wp-block-image"><img src="http://localhost/wp-content/uploads/2018/01/Dec-08-2017-15-12-24-17-300x137.gif" alt="" /></figure>
<!-- /wp:image -->
4 changes: 4 additions & 0 deletions blocks/api/raw-handling/test/integration/two-images-in.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<img class="alignnone wp-image-5114 size-medium" src="http://localhost/wp-content/uploads/2018/01/Dec-08-2017-15-12-24-17-300x137.gif" alt="" width="300" height="137" />


<img class="alignnone wp-image-5109 size-medium" src="http://localhost/wp-content/uploads/2018/01/Dec-05-2017-17-52-09-9-300x248.gif" alt="" width="300" height="248" />
7 changes: 7 additions & 0 deletions blocks/api/raw-handling/test/integration/two-images-out.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- wp:image -->
<figure class="wp-block-image"><img src="http://localhost/wp-content/uploads/2018/01/Dec-08-2017-15-12-24-17-300x137.gif" alt="" /></figure>
<!-- /wp:image -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="http://localhost/wp-content/uploads/2018/01/Dec-05-2017-17-52-09-9-300x248.gif" alt="" /></figure>
<!-- /wp:image -->
6 changes: 2 additions & 4 deletions blocks/library/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ export const settings = {
return tag === 'img' || ( hasImage && ! hasText ) || ( hasImage && tag === 'figure' );
},
transform( node ) {
const targetNode = node.parentNode.querySelector( 'figure,img' );
const matches = /align(left|center|right)/.exec( targetNode.className );
const matches = /align(left|center|right)/.exec( node.className );
const align = matches ? matches[ 1 ] : undefined;
const blockType = getBlockType( 'core/image' );
const attributes = getBlockAttributes( blockType, targetNode.outerHTML, { align } );

const attributes = getBlockAttributes( blockType, node.outerHTML, { align } );
return createBlock( 'core/image', attributes );
},
},
Expand Down

0 comments on commit 773f27c

Please sign in to comment.