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
Fix using the classic block in nested contexts #16477
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,17 +255,18 @@ export function getCommentDelimitedContent( rawBlockName, attributes, content ) | |
* Returns the content of a block, including comment delimiters, determining | ||
* serialized attributes and content form from the current state of the block. | ||
* | ||
* @param {Object} block Block instance. | ||
* @param {Object} block Block instance. | ||
* @param {Object} options Serialization options. | ||
* | ||
* @return {string} Serialized block. | ||
*/ | ||
export function serializeBlock( block ) { | ||
export function serializeBlock( block, { isNested = false } = {} ) { | ||
const blockName = block.name; | ||
const saveContent = getBlockContent( block ); | ||
|
||
switch ( blockName ) { | ||
case getFreeformContentHandlerName(): | ||
case getUnregisteredTypeHandlerName(): | ||
switch ( true ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point, I think we'd just not want to bother with a switch ( blockName ) {
case getUnregisteredTypeHandlerName():
return saveContent;
case getFreeformContentHandlerName():
if ( ! isNested ) {
return saveContent;
}
default: {
const blockType = getBlockType( blockName );
const saveAttributes = getCommentAttributes( blockType, block.attributes );
return getCommentDelimitedContent( blockName, saveAttributes, saveContent );
}
} It's pretty confusing though. Maybe less-so if |
||
case ! isNested && blockName === getFreeformContentHandlerName(): | ||
case blockName === getUnregisteredTypeHandlerName(): | ||
return saveContent; | ||
|
||
default: { | ||
|
@@ -280,9 +281,12 @@ export function serializeBlock( block ) { | |
* Takes a block or set of blocks and returns the serialized post content. | ||
* | ||
* @param {Array} blocks Block(s) to serialize. | ||
* @param {Object} options Serialization options. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should document these options. I think the "best" way would to define a JSDoc typedef of something like |
||
* | ||
* @return {string} The post content. | ||
*/ | ||
export default function serialize( blocks ) { | ||
return castArray( blocks ).map( serializeBlock ).join( '\n\n' ); | ||
export default function serialize( blocks, options ) { | ||
return castArray( blocks ) | ||
.map( ( block ) => serializeBlock( block, options ) ) | ||
.join( '\n\n' ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think we should try to consolidate our vocabulary around "inner blocks". Do we have many other references of "nested" in code? I know there's a tendency to refer to them this way in casual conversation. Is
isInnerBlock
reasonable as an alternative here?