From 469f349bdbb9806cf7a56d8f14d5758f6e9c990c Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Thu, 25 Jul 2024 17:28:47 -0400 Subject: [PATCH] Fix support for blockquote --- src/class-block-converter.php | 25 +++++++++++++++++++++++++ tests/feature/BlockConverterTest.php | 8 ++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/class-block-converter.php b/src/class-block-converter.php index a95002a..0e34f00 100644 --- a/src/class-block-converter.php +++ b/src/class-block-converter.php @@ -148,8 +148,33 @@ protected function h( DOMNode $node ): ?Block { * @return Block|null */ protected function blockquote( DOMNode $node ): ?Block { + // Set the class on the node equal to wp-block-quote. + if ( $node instanceof DOMElement && empty( $node->getAttribute( 'class' ) ) ) { + $node->setAttribute( 'class', 'wp-block-quote' ); + } + + $children = ''; + + // Recursively convert the children of the blockquote to blocks. + foreach ( $node->childNodes as $child ) { + $child_block = $this->{$child->nodeName}( $child ); + + if ( ! empty( $child_block ) ) { + $children .= $this->minify_block( (string) $child_block ); + } + } + + // Replace the children with a placeholder that will be replaced with + // the children after the blockquote is converted to block. + if ( ! empty( $node->nodeValue ) ) { + $node->nodeValue = '__CHILDREN__'; + } + $content = static::get_node_html( $node ); + // Replace the closing blockquote tag with the children. + $content = str_replace( '__CHILDREN__', $children, $content ); + if ( empty( $content ) ) { return null; } diff --git a/tests/feature/BlockConverterTest.php b/tests/feature/BlockConverterTest.php index b9f6538..14ad854 100644 --- a/tests/feature/BlockConverterTest.php +++ b/tests/feature/BlockConverterTest.php @@ -82,10 +82,10 @@ public static function converter_data_provider() { '', '', ], - // 'blockquote' => [ - // '

Lorem ipsum

', - // '

Lorem ipsum

', - // ], + 'blockquote' => [ + '

Lorem ipsum

', + '

Lorem ipsum

', + ], 'non-oembed-embed' => [ '', '',