Skip to content

Commit

Permalink
Change content parser to enter <body> tag on start, adjust raw source…
Browse files Browse the repository at this point in the history
… attributes to match
  • Loading branch information
alecgeatches committed Jul 30, 2024
1 parent b555b30 commit 003e525
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/parser/content-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ protected function source_block( $block, $registered_blocks, $filter_options ) {
$crawler = new Crawler( sprintf( '<!doctype html><html><body>%s</body></html>', $block['innerHTML'] ) );

// Enter the <body> tag for block parsing.
$crawler = $crawler->filter( 'body' );
$crawler = $crawler->filter( 'body' )->children();

$attribute_value = $this->source_attribute( $crawler, $block_attribute_definition );

Expand Down Expand Up @@ -313,11 +313,11 @@ protected function source_attribute( $crawler, $block_attribute_definition ) {

$attribute_value = $this->source_block_attribute( $crawler, $block_attribute_definition );
} elseif ( 'rich-text' === $attribute_source ) {
$attribute_value = $this->source_block_rich_text( $crawler, $block_attribute_definition );
} elseif ( 'html' === $attribute_source ) {
// Most 'html' sources were converted to 'rich-text' in WordPress 6.5.
// https://github.com/WordPress/gutenberg/pull/43204

$attribute_value = $this->source_block_rich_text( $crawler, $block_attribute_definition );
} elseif ( 'html' === $attribute_source ) {
$attribute_value = $this->source_block_html( $crawler, $block_attribute_definition );
} elseif ( 'text' === $attribute_source ) {
$attribute_value = $this->source_block_text( $crawler, $block_attribute_definition );
Expand Down Expand Up @@ -552,7 +552,7 @@ protected function source_block_raw( $crawler ) {
$attribute_value = null;

if ( $crawler->count() > 0 ) {
$attribute_value = trim( $crawler->html() );
$attribute_value = trim( $crawler->outerHtml() );
}

return $attribute_value;
Expand Down

0 comments on commit 003e525

Please sign in to comment.