diff --git a/blocks/api/serializer.js b/blocks/api/serializer.js index 88b07a63072c0..b43dd3455d1bc 100644 --- a/blocks/api/serializer.js +++ b/blocks/api/serializer.js @@ -53,14 +53,10 @@ export function getCommentAttributes( realAttributes, expectedAttributes ) { ); // Serialize the comment attributes - return keys.reduce( ( memo, key ) => { - const value = realAttributes[ key ]; - if ( undefined === value ) { - return memo; - } - - return memo + `${ key }="${ value }" `; - }, '' ); + return keys + .filter( key => undefined !== realAttributes[ key ] ) + .map( key => `${ key }="${ realAttributes[ key ] }"` ) + .join( ' ' ); } /** @@ -70,28 +66,26 @@ export function getCommentAttributes( realAttributes, expectedAttributes ) { * @return {String} The post content */ export default function serialize( blocks ) { - return blocks.reduce( ( memo, block ) => { - const blockType = block.blockType; - const settings = getBlockSettings( blockType ); - const saveContent = getSaveContent( settings.save, block.attributes ); - const beautifyOptions = { - indent_inner_html: true, - wrap_line_length: 0, - }; - - return memo + ( - '' + - ( saveContent ? '\n' + beautifyHtml( saveContent, beautifyOptions ) + '\n' : '' ) + - '' - ) + '\n\n'; - }, '' ); + ); + + return [ + ``, + saveContent ? beautifyHtml( saveContent, beautifyOptions ) : undefined, + ``, + ].join( '\n' ); + } ) + .join( '\n\n' ) + .concat( '\n\n' ); // since we no longer have off-by-one-errors with spacing, we may not need this } diff --git a/blocks/api/test/serializer.js b/blocks/api/test/serializer.js index 493cddeec2bb0..804f05fa899c4 100644 --- a/blocks/api/test/serializer.js +++ b/blocks/api/test/serializer.js @@ -71,7 +71,7 @@ describe( 'block serializer', () => { fruit: 'bananas', } ); - expect( attributes ).to.equal( 'category="food" ripeness="ripe" ' ); + expect( attributes ).to.equal( 'category="food" ripeness="ripe"' ); } ); it( 'should not append an undefined attribute value', () => { @@ -83,7 +83,7 @@ describe( 'block serializer', () => { fruit: 'bananas', } ); - expect( attributes ).to.equal( 'category="food" ' ); + expect( attributes ).to.equal( 'category="food"' ); } ); } );