Skip to content

Commit

Permalink
Parser: Add "void" block signature
Browse files Browse the repository at this point in the history
Sometimes a block doesn't need anything inside of the block comment tags
as children. One example of this is the traditional "more tag," which
only needs to indicate position.

These changes introduce a new syntax element, the "void block,"
borrowing from the HTML5 nomenclature for HTML void elements.

In this new element, there are no children.

Since nothing changes on the JavaScript size this could be considered an
optimization whereby any block with no children serializes to a
self-closing block comment tag, saving some space and improving
readability of the `post_content`.
  • Loading branch information
dmsnell committed Jun 12, 2017
1 parent ec593f1 commit af617a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion blocks/api/post.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ WP_Block_List
= WP_Block*

WP_Block
= WP_Block_Balanced
= WP_Block_Void
/ WP_Block_Balanced
/ WP_Block_Html

WP_Block_Void
= "<!--" __ "wp:" blockType:WP_Block_Type attrs:HTML_Attribute_List _? "/-->"
{ return {
blockType: blockType,
attrs: attrs,
rawContent: ''
} }

WP_Block_Balanced
= s:WP_Block_Start ts:(!WP_Block_End c:Any { return c })* e:WP_Block_End & { return s.blockType === e.blockType }
{ return {
Expand Down
2 changes: 2 additions & 0 deletions post-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ window._wpGutenbergPost = {
'<p style="text-align:right;">... like this one, which is separate from the above and right aligned.</p>',
'<!-- /wp:core/text -->',

'<!-- wp:core/more /-->',

'<!-- wp:core/text -->',
'<p>Headings are separate blocks as well, which helps with the outline and organization of your content.</p>',
'<!-- /wp:core/text -->',
Expand Down

0 comments on commit af617a2

Please sign in to comment.