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

Save DOMDocument node instead of root + str_replace #25020

Merged
merged 3 commits into from
Sep 2, 2020
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
2 changes: 1 addition & 1 deletion lib/block-supports/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function gutenberg_apply_block_supports( $block_content, $block ) {
$block_root->setAttribute( 'style', esc_attr( implode( '; ', $new_styles ) . ';' ) );
}

return str_replace( array( $wrapper_left, $wrapper_right ), '', $dom->saveHtml() );
return $dom->saveHtml( $block_root );
}
add_filter( 'render_block', 'gutenberg_apply_block_supports', 10, 2 );

Expand Down
10 changes: 7 additions & 3 deletions phpunit/class-block-supported-styles-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ private function assert_styles_and_classes_match( $block, $expected_classes, $ex
*/
private function assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ) {
$styled_block = apply_filters( 'render_block', self::BLOCK_MARKUP, $block );
$content = $this->get_content_from_block( $styled_block );
$class_list = $this->get_attribute_from_block( 'class', $styled_block );
$style_list = $this->get_attribute_from_block( 'style', $styled_block );

// Ensure blocks to not add extra whitespace.
$this->assertEquals( $styled_block, trim( $styled_block ) );

$content = $this->get_content_from_block( $styled_block );
$class_list = $this->get_attribute_from_block( 'class', $styled_block );
$style_list = $this->get_attribute_from_block( 'style', $styled_block );

$this->assertEquals( self::BLOCK_CONTENT, $content );
$this->assertEquals( $expected_classes, $class_list );
Expand Down