diff --git a/blocks/api/parser.js b/blocks/api/parser.js
index 648f0bc363c67..fa1a1ad201e49 100644
--- a/blocks/api/parser.js
+++ b/blocks/api/parser.js
@@ -99,7 +99,7 @@ export function parseWithTinyMCE( content ) {
// In :
// Out :
Broccoli
' + - 'Ribs' - ); - - expect( parsed ).to.have.lengthOf( 1 ); - expect( parsed[ 0 ].blockType ).to.equal( 'core/test-block' ); - expect( parsed[ 0 ].attributes ).to.eql( { - content: 'Ribs & Chicken' - } ); - expect( parsed[ 0 ].uid ).to.be.a( 'string' ); - } ); - - it( 'should parse the post content, using unknown block handler', () => { - registerBlock( 'core/test-block', {} ); - registerBlock( 'core/unknown-block', {} ); - - setUnknownTypeHandler( 'core/unknown-block' ); - - const parsed = parse( - 'Ribs' + - 'Broccoli
' + - 'Ribs' - ); - - expect( parsed ).to.have.lengthOf( 3 ); - expect( parsed.map( ( { blockType } ) => blockType ) ).to.eql( [ - 'core/test-block', - 'core/unknown-block', - 'core/unknown-block', - ] ); - } ); - - it( 'should parse the post content, including raw HTML at each end', () => { - registerBlock( 'core/test-block', {} ); - registerBlock( 'core/unknown-block', { - // Currently this is the only way to test block content parsing? - attributes: function( rawContent ) { - return { - content: rawContent, - }; - } + const parsers = { parseWithTinyMCE, parseWithGrammar }; + Object.keys( parsers ).forEach( ( parser ) => { + const parse = parsers[ parser ]; + describe( parser, () => { + it( 'should parse the post content, including block attributes', () => { + registerBlock( 'core/test-block', { + // Currently this is the only way to test block content parsing? + attributes: function( rawContent ) { + return { + content: rawContent, + }; + } + } ); + + const parsed = parse( + '' + + 'Brisket' + + '' + ); + + expect( parsed ).to.have.lengthOf( 1 ); + expect( parsed[ 0 ].blockType ).to.equal( 'core/test-block' ); + expect( parsed[ 0 ].attributes ).to.eql( { + content: 'Brisket', + smoked: 'yes', + url: 'http://google.com', + chicken: 'ribs & \'wings\'', + checked: true + } ); + expect( parsed[ 0 ].uid ).to.be.a( 'string' ); + } ); + + it( 'should parse the post content, ignoring unknown blocks', () => { + registerBlock( 'core/test-block', { + attributes: function( rawContent ) { + return { + content: rawContent + ' & Chicken' + }; + } + } ); + + const parsed = parse( + 'Ribs' + + 'Broccoli
' + + 'Ribs' + ); + + expect( parsed ).to.have.lengthOf( 1 ); + expect( parsed[ 0 ].blockType ).to.equal( 'core/test-block' ); + expect( parsed[ 0 ].attributes ).to.eql( { + content: 'Ribs & Chicken' + } ); + expect( parsed[ 0 ].uid ).to.be.a( 'string' ); + } ); + + it( 'should parse the post content, using unknown block handler', () => { + registerBlock( 'core/test-block', {} ); + registerBlock( 'core/unknown-block', {} ); + + setUnknownTypeHandler( 'core/unknown-block' ); + + const parsed = parse( + 'Ribs' + + 'Broccoli
' + + 'Ribs' + ); + + expect( parsed ).to.have.lengthOf( 3 ); + expect( parsed.map( ( { blockType } ) => blockType ) ).to.eql( [ + 'core/test-block', + 'core/unknown-block', + 'core/unknown-block', + ] ); + } ); + + it( 'should parse the post content, including raw HTML at each end', () => { + registerBlock( 'core/test-block', {} ); + registerBlock( 'core/unknown-block', { + // Currently this is the only way to test block content parsing? + attributes: function( rawContent ) { + return { + content: rawContent, + }; + } + } ); + + setUnknownTypeHandler( 'core/unknown-block' ); + + const parsed = parse( + 'Cauliflower
' + + 'Ribs' + + 'Broccoli
' + + 'Ribs' + + 'Romanesco
' + ); + + expect( parsed ).to.have.lengthOf( 5 ); + expect( parsed.map( ( { blockType } ) => blockType ) ).to.eql( [ + 'core/unknown-block', + 'core/test-block', + 'core/unknown-block', + 'core/test-block', + 'core/unknown-block', + ] ); + expect( parsed[ 0 ].attributes.content ).to.eql( 'Cauliflower
' ); + expect( parsed[ 2 ].attributes.content ).to.eql( 'Broccoli
' ); + expect( parsed[ 4 ].attributes.content ).to.eql( 'Romanesco
' ); + } ); } ); - - setUnknownTypeHandler( 'core/unknown-block' ); - - const parsed = parse( - 'Cauliflower
' + - 'Ribs' + - 'Broccoli
' + - 'Ribs' + - 'Romanesco
' - ); - - expect( parsed ).to.have.lengthOf( 5 ); - expect( parsed.map( ( { blockType } ) => blockType ) ).to.eql( [ - 'core/unknown-block', - 'core/test-block', - 'core/unknown-block', - 'core/test-block', - 'core/unknown-block', - ] ); - expect( parsed[ 0 ].attributes.content ).to.eql( 'Cauliflower
' ); - expect( parsed[ 2 ].attributes.content ).to.eql( 'Broccoli
' ); - expect( parsed[ 4 ].attributes.content ).to.eql( 'Romanesco
' ); } ); } ); } ); diff --git a/post-content.js b/post-content.js index bbadbcddb7b80..dc4371e22288b 100644 --- a/post-content.js +++ b/post-content.js @@ -41,7 +41,7 @@ window._wpGutenbergPost = { '