Skip to content

Commit

Permalink
Fix support for blockquote
Browse files Browse the repository at this point in the history
  • Loading branch information
srtfisher committed Jul 25, 2024
1 parent d5c8c0e commit 469f349
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/class-block-converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/feature/BlockConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public static function converter_data_provider() {
'<ul><li>Random content</li><li>Another random content</li></ul>',
'<!-- wp:list --><ul><li>Random content</li><li>Another random content</li></ul><!-- /wp:list -->',
],
// 'blockquote' => [
// '<blockquote><p>Lorem ipsum</p></blockquote>',
// '<!-- wp:quote --><blockquote class="wp-block-quote"><!-- wp:paragraph --><p>Lorem ipsum</p><!-- /wp:paragraph --></blockquote><!-- /wp:quote -->',
// ],
'blockquote' => [
'<blockquote><p>Lorem ipsum</p></blockquote>',
'<!-- wp:quote --><blockquote class="wp-block-quote"><!-- wp:paragraph --><p>Lorem ipsum</p><!-- /wp:paragraph --></blockquote><!-- /wp:quote -->',
],
'non-oembed-embed' => [
'<embed type="video/webm" src="/media/mr-arnold.mp4" width="250" height="200" />',
'<!-- wp:html --><embed type="video/webm" src="/media/mr-arnold.mp4" width="250" height="200"></embed><!-- /wp:html -->',
Expand Down

0 comments on commit 469f349

Please sign in to comment.