Skip to content
Open
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
14 changes: 11 additions & 3 deletions packages/blocks/src/api/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,18 @@ export function parseRawBlock(
// It might be a good idea to throw a warning here.
// TODO: I'm unsure about the unregisteredFallbackBlock check,
// it might ignore some dynamic unregistered third party blocks wrongly.
const isFallbackBlock =
normalizedBlock.blockName === getFreeformContentHandlerName() ||
const isUnregisteredBlock =
normalizedBlock.blockName === getUnregisteredTypeHandlerName();
if ( ! blockType || ( ! normalizedBlock.innerHTML && isFallbackBlock ) ) {

const isImplicitFreeformBlock =
normalizedBlock.blockName === getFreeformContentHandlerName() &&
rawBlock.blockName !== getFreeformContentHandlerName();

if (
! blockType ||
( ! normalizedBlock.innerHTML &&
( isUnregisteredBlock || isImplicitFreeformBlock ) )
) {
return;
}

Expand Down
7 changes: 4 additions & 3 deletions packages/blocks/src/api/raw-handling/paste-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ export function pasteHandler( {

if ( content.indexOf( '<!-- wp:' ) !== -1 ) {
const parseResult = parse( content );
const isSingleFreeFormBlock =
const isSingleNonEmptyFreeFormBlock =
parseResult.length === 1 &&
parseResult[ 0 ].name === 'core/freeform';
if ( ! isSingleFreeFormBlock ) {
parseResult[ 0 ].name === 'core/freeform' &&
parseResult[ 0 ].attributes?.content;
if ( ! isSingleNonEmptyFreeFormBlock ) {
return parseResult;
}
}
Expand Down
13 changes: 9 additions & 4 deletions packages/blocks/src/api/serializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,18 @@ export function serializeBlock(
const blockName = block.name;
const saveContent = getBlockInnerHTML( block );

if (
blockName === getUnregisteredTypeHandlerName() ||
( ! isInnerBlocks && blockName === getFreeformContentHandlerName() )
) {
if ( blockName === getUnregisteredTypeHandlerName() ) {
return saveContent;
}

if ( ! isInnerBlocks && blockName === getFreeformContentHandlerName() ) {
if ( saveContent ) {
return saveContent;
}

return getCommentDelimitedContent( blockName, {}, saveContent );
}

const blockType = getBlockType( blockName );
if ( ! blockType ) {
return saveContent;
Expand Down
Loading