Blocks: Parse blocks when displaying posts.

Posts containing blocks are now correctly handled when displaying on the front end, including dynamic blocks and nested blocks.

Props pento.

Merges [43752] to trunk.

See #45109.

git-svn-id: https://develop.svn.wordpress.org/trunk@44118 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers
2018-12-13 18:11:10 +00:00
parent 6aef7e1966
commit 93091fac36
71 changed files with 1419 additions and 24 deletions

View File

@@ -310,9 +310,16 @@ class WP_Block_Parser {
* otherwise we're nested and we have to close out the current
* block and add it as a new innerBlock to the parent
*/
$stack_top = array_pop( $this->stack );
$stack_top->block->innerHTML .= substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
$stack_top->prev_offset = $start_offset + $token_length;
$stack_top = array_pop( $this->stack );
$html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );
if ( $stack_top->block->innerBlocks ) {
$stack_top->block->innerBlocks[] = (array) $this->freeform( $html );
} else {
$stack_top->block->innerHTML = $html;
}
$stack_top->prev_offset = $start_offset + $token_length;
$this->add_inner_block(
$stack_top->block,
@@ -445,8 +452,8 @@ class WP_Block_Parser {
*/
function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) {
$parent = $this->stack[ count( $this->stack ) - 1 ];
$parent->block->innerBlocks[] = $block;
$parent->block->innerHTML .= substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );
$parent->block->innerBlocks[] = (array) $this->freeform( substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset ) );
$parent->block->innerBlocks[] = (array) $block;
$parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length;
}
@@ -461,10 +468,16 @@ class WP_Block_Parser {
$stack_top = array_pop( $this->stack );
$prev_offset = $stack_top->prev_offset;
$stack_top->block->innerHTML .= isset( $end_offset )
$html = isset( $end_offset )
? substr( $this->document, $prev_offset, $end_offset - $prev_offset )
: substr( $this->document, $prev_offset );
if ( $stack_top->block->innerBlocks ) {
$stack_top->block->innerBlocks[] = (array) $this->freeform( $html );
} else {
$stack_top->block->innerHTML = $html;
}
if ( isset( $stack_top->leading_html_start ) ) {
$this->output[] = (array) self::freeform(
substr(