From 06be7cafcb64f5a860cdb79bfaa8dc6858a376a3 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Mon, 12 Jun 2017 23:36:56 +0200 Subject: [PATCH] Parser: Add "void" block signature (#1134) --- blocks/api/post.pegjs | 11 ++++++++++- blocks/api/serializer.js | 12 +++++++----- blocks/test/fixtures/core-button-center.html | 2 +- blocks/test/fixtures/core-freeform.json | 7 ++++--- blocks/test/fixtures/core-freeform.serialized.html | 4 +++- blocks/test/fixtures/core-latestposts.html | 2 +- .../test/fixtures/core-latestposts.serialized.html | 2 +- blocks/test/fixtures/core-text-multi-paragraph.json | 1 + blocks/test/full-content.js | 7 ++----- post-content.js | 2 ++ 10 files changed, 32 insertions(+), 18 deletions(-) diff --git a/blocks/api/post.pegjs b/blocks/api/post.pegjs index e53d9fa530524b..e45139e048e3e7 100644 --- a/blocks/api/post.pegjs +++ b/blocks/api/post.pegjs @@ -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 + = "" + { 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 { diff --git a/blocks/api/serializer.js b/blocks/api/serializer.js index 9080e853f144fe..5ccd305befc454 100644 --- a/blocks/api/serializer.js +++ b/blocks/api/serializer.js @@ -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 + '\n\n'; + } return memo + ( '' + - ( saveContent ? '\n' + beautifyHtml( saveContent, beautifyOptions ) + '\n' : '' ) + + '\n' + beautifyHtml( saveContent, beautifyOptions ) + '\n' + '' diff --git a/blocks/test/fixtures/core-button-center.html b/blocks/test/fixtures/core-button-center.html index e19e0ed3fc4d6e..b80f97864c2935 100644 --- a/blocks/test/fixtures/core-button-center.html +++ b/blocks/test/fixtures/core-button-center.html @@ -1,3 +1,3 @@ -
Help build Gutenberg
+
Help build Gutenberg
diff --git a/blocks/test/fixtures/core-freeform.json b/blocks/test/fixtures/core-freeform.json index 09a99fbee8aa5d..c12160e9584178 100644 --- a/blocks/test/fixtures/core-freeform.json +++ b/blocks/test/fixtures/core-freeform.json @@ -4,13 +4,13 @@ "name": "core/freeform", "attributes": { "content": [ - "Testing freeform block with some", + "Testing freeform block with some\n", { "attributes": { "className": "wp-some-class" }, "children": [ - "HTML ", + "\n\tHTML ", { "attributes": { "style": { @@ -19,7 +19,8 @@ }, "children": "content", "type": "span" - } + }, + "\n" ], "type": "div" } diff --git a/blocks/test/fixtures/core-freeform.serialized.html b/blocks/test/fixtures/core-freeform.serialized.html index 4ce56fd27af8e9..d30114895dd4c6 100644 --- a/blocks/test/fixtures/core-freeform.serialized.html +++ b/blocks/test/fixtures/core-freeform.serialized.html @@ -1,5 +1,7 @@ Testing freeform block with some -
HTML content
+
+ HTML content +
diff --git a/blocks/test/fixtures/core-latestposts.html b/blocks/test/fixtures/core-latestposts.html index cc09cb936f430a..811b2260df7382 100644 --- a/blocks/test/fixtures/core-latestposts.html +++ b/blocks/test/fixtures/core-latestposts.html @@ -1,2 +1,2 @@ - + diff --git a/blocks/test/fixtures/core-latestposts.serialized.html b/blocks/test/fixtures/core-latestposts.serialized.html index cc09cb936f430a..811b2260df7382 100644 --- a/blocks/test/fixtures/core-latestposts.serialized.html +++ b/blocks/test/fixtures/core-latestposts.serialized.html @@ -1,2 +1,2 @@ - + diff --git a/blocks/test/fixtures/core-text-multi-paragraph.json b/blocks/test/fixtures/core-text-multi-paragraph.json index 4760696210f6b2..fd29811801eff6 100644 --- a/blocks/test/fixtures/core-text-multi-paragraph.json +++ b/blocks/test/fixtures/core-text-multi-paragraph.json @@ -15,6 +15,7 @@ "—somewhat similar to LEGO bricks—that you can move around and interact with. Move your cursor around and you'll notice the different blocks light up with outlines and arrows. Press the arrows to reposition blocks quickly, without fearing about losing things in the process of copying and pasting." ] }, + "\n", { "type": "p", "children": [ diff --git a/blocks/test/full-content.js b/blocks/test/full-content.js index 4bdf65b03bac7f..26ab2a09a60b4c 100644 --- a/blocks/test/full-content.js +++ b/blocks/test/full-content.js @@ -10,10 +10,7 @@ import { format } from 'util'; /** * Internal dependencies */ -import { - // parseWithGrammar, - parseWithTinyMCE, -} from '../api/parser'; +import parse from '../api/parser'; import serialize from '../api/serializer'; import { getBlockTypes } from '../api/registration'; @@ -94,7 +91,7 @@ describe( 'full post content fixture', () => { it( f, () => { const content = readFixtureFile( f + '.html' ); - const blocksActual = parseWithTinyMCE( content ); + const blocksActual = parse( content ); const blocksActualNormalized = normalizeParsedBlocks( blocksActual ); let blocksExpectedString = readFixtureFile( f + '.json' ); diff --git a/post-content.js b/post-content.js index 33b6cc98a13535..8317d2b64ae3a6 100644 --- a/post-content.js +++ b/post-content.js @@ -16,6 +16,8 @@ window._wpGutenbergPost = { '

... like this one, which is separate from the above and right aligned.

', '', + '', + '', '

Headings are separate blocks as well, which helps with the outline and organization of your content.

', '',