Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paste: check plain text for Gutenberg content #14536

Merged
merged 1 commit into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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;
ellatrix marked this conversation as resolved.
Show resolved Hide resolved
ellatrix marked this conversation as resolved.
Show resolved Hide resolved

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