Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix HTML content appearing at the beginning of a post's content
  • Loading branch information
nylen committed Apr 18, 2017
commit ed7747a246f0f9953409517b79a7990dfcd151bf
1 change: 1 addition & 0 deletions blocks/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export default function parse( content ) {
}
contentBetweenBlocks = new tinymce.html.Node( 'body', 11 );
}
flushContentBetweenBlocks();

let currentNode = tree.firstChild;
do {
Expand Down
11 changes: 7 additions & 4 deletions blocks/api/test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe( 'block parser', () => {
] );
} );

it( 'should parse the post content, using unknown block handler at the end of the 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?
Expand All @@ -158,21 +158,24 @@ describe( 'block parser', () => {
setUnknownTypeHandler( 'core/unknown-block' );

const parsed = parse(
'<p>Cauliflower</p>' +
'<!-- wp:core/test-block -->Ribs<!-- /wp:core/test-block -->' +
'<p>Broccoli</p>' +
'<!-- wp:core/test-block -->Ribs<!-- /wp:core/test-block -->' +
'<p>Romanesco</p>'
);

expect( parsed ).to.have.lengthOf( 4 );
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[ 1 ].attributes.content ).to.eql( '<p>Broccoli</p>' );
expect( parsed[ 3 ].attributes.content ).to.eql( '<p>Romanesco</p>' );
expect( parsed[ 0 ].attributes.content ).to.eql( '<p>Cauliflower</p>' );
expect( parsed[ 2 ].attributes.content ).to.eql( '<p>Broccoli</p>' );
expect( parsed[ 4 ].attributes.content ).to.eql( '<p>Romanesco</p>' );
} );
} );
} );