Skip to content

Commit

Permalink
Paste: check plain text for gutenberg content (#14536)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Mar 21, 2019
1 parent 91269ae commit 1b10520
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/blocks/src/api/raw-handling/paste-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,14 @@ export function pasteHandler( { HTML = '', plainText = '', mode = 'AUTO', tagNam
// First of all, strip any meta tags.
HTML = HTML.replace( /<meta[^>]+>/, '' );

// If we detect block delimiters, parse entirely as blocks.
if ( mode !== 'INLINE' && HTML.indexOf( '<!-- wp:' ) !== -1 ) {
return parseWithGrammar( HTML );
// If we detect block delimiters in HTML, parse entirely as blocks.
if ( mode !== 'INLINE' ) {
// Check plain text if there is no HTML.
const content = HTML ? HTML : plainText;

if ( content.indexOf( '<!-- wp:' ) !== -1 ) {
return parseWithGrammar( content );
}
}

// Normalize unicode to use composed characters.
Expand Down
8 changes: 8 additions & 0 deletions test/integration/blocks-raw-handling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ describe( 'Blocks raw handling', () => {
expect( console ).toHaveLogged();
} );

it( 'should paste gutenberg content from plain text', () => {
const block = '<!-- wp:latest-posts /-->';
expect( serialize( pasteHandler( {
plainText: block,
mode: 'AUTO',
} ) ) ).toBe( block );
} );

describe( 'pasteHandler', () => {
[
'plain',
Expand Down

0 comments on commit 1b10520

Please sign in to comment.