Skip to content

Commit

Permalink
Update serializer to use void block if no children exist for block
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Jun 12, 2017
1 parent af617a2 commit 127aecb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions blocks/api/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,19 @@ export default function serialize( blocks ) {
indent_inner_html: true,
wrap_line_length: 0,
};
const blockAttributes = getCommentAttributes( block.attributes, parseBlockAttributes( saveContent, blockType ) );

if ( ! saveContent ) {
return memo + '<!-- wp:' + blockName + ' ' + blockAttributes + '/-->\n\n';
}

return memo + (
'<!-- wp:' +
blockName +
' ' +
getCommentAttributes(
block.attributes,
parseBlockAttributes( saveContent, blockType )
) +
blockAttributes +
'-->' +
( saveContent ? '\n' + beautifyHtml( saveContent, beautifyOptions ) + '\n' : '' ) +
'\n' + beautifyHtml( saveContent, beautifyOptions ) + '\n' +
'<!-- /wp:' +
blockName +
' -->'
Expand Down
2 changes: 1 addition & 1 deletion blocks/test/fixtures/core-latestposts.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- wp:core/latestposts poststoshow="5" --><!-- /wp:core/latestposts -->
<!-- wp:core/latestposts poststoshow="5" /-->

2 changes: 1 addition & 1 deletion blocks/test/fixtures/core-latestposts.serialized.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- wp:core/latestposts poststoshow="5" --><!-- /wp:core/latestposts -->
<!-- wp:core/latestposts poststoshow="5" /-->

0 comments on commit 127aecb

Please sign in to comment.