Skip to content

Commit

Permalink
Raw handling: preserve class (WordPress#60331)
Browse files Browse the repository at this point in the history
Unlinked contributors: galbaras.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: ndiego <ndiego@git.wordpress.org>
  • Loading branch information
4 people authored and cbravobernal committed Apr 9, 2024
1 parent 022c589 commit 8471076
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/blocks/src/api/raw-handling/html-to-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export function htmlToBlocks( html, handler ) {
const { transform, blockName } = rawTransform;

if ( transform ) {
return transform( node, handler );
const block = transform( node, handler );
if ( node.hasAttribute( 'class' ) ) {
block.attributes.className = node.getAttribute( 'class' );
}
return block;
}

return createBlock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ exports[`rawHandler should preserve all paragraphs 1`] = `
<p>&nbsp;&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- wp:paragraph {"className":"p"} -->
<p class="p"></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ exports[`Blocks raw handling pasteHandler wordpress 1`] = `"Howdy<br>This is a p

exports[`Blocks raw handling should correctly handle quotes with mixed content 1`] = `
"<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:heading {"level":1} -->
<blockquote class="wp-block-quote"><!-- wp:heading {"level":1,"className":"wp-block-heading"} -->
<h1 class="wp-block-heading">chicken</h1>
<!-- /wp:heading -->
Expand Down

0 comments on commit 8471076

Please sign in to comment.