-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add block class name to the list block (#56469)
Adds the `wp-block-list` class name to the list block in the editor and front. This means that global styles applied to `core/list` affects the list block, instead of affecting all lists. Ensures that pre-existing list blocks use the class name on the front, `<ol>` is transformed to `<ol class="wp-block-list">`. Deprecates the version of the list block that did not support `className`. The ` __experimentalSelector` on the list item block is changed to `.wp-block-list > li`, Updates tests and test fixtures that use the list block. Co-authored-by: carolinan <[email protected]> Co-authored-by: tellthemachines <[email protected]> Co-authored-by: mtias <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: fabiankaegy <[email protected]>
- Loading branch information
1 parent
802519e
commit 83ddbfb
Showing
39 changed files
with
406 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Adds the wp-block-list class to the rendered list block. | ||
* | ||
* @package WordPress | ||
*/ | ||
|
||
/** | ||
* Adds the wp-block-list class to the rendered list block. | ||
* Ensures that pre-existing list blocks use the class name on the front. | ||
* For example, <ol> is transformed to <ol class="wp-block-list">. | ||
* | ||
* @since 6.6.0 | ||
* | ||
* @see https://github.com/WordPress/gutenberg/issues/12420 | ||
* | ||
* @param array $attributes Attributes of the block being rendered. | ||
* @param string $content Content of the block being rendered. | ||
* | ||
* @return string The content of the block being rendered. | ||
*/ | ||
function block_core_list_render( $attributes, $content ) { | ||
if ( ! $content ) { | ||
return $content; | ||
} | ||
|
||
$processor = new WP_HTML_Tag_Processor( $content ); | ||
|
||
$list_tags = array( 'OL', 'UL' ); | ||
while ( $processor->next_tag() ) { | ||
if ( in_array( $processor->get_tag(), $list_tags, true ) ) { | ||
$processor->add_class( 'wp-block-list' ); | ||
break; | ||
} | ||
} | ||
|
||
return $processor->get_updated_html(); | ||
} | ||
|
||
/** | ||
* Registers the `core/list` block on server. | ||
* | ||
* @since 6.6.0 | ||
*/ | ||
function register_block_core_list() { | ||
register_block_type_from_metadata( | ||
__DIR__ . '/list', | ||
array( | ||
'render_callback' => 'block_core_list_render', | ||
) | ||
); | ||
} | ||
|
||
add_action( 'init', 'register_block_core_list' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.