-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add block class name to the list block #56469
Merged
+406
−168
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
df25bf5
Add server-side block class names to the list blocks
carolinan 01105c7
fix CS issues
carolinan b870eed
Deprecate the block version that has the className block support set …
carolinan 60d225d
Merge branch 'trunk' into add/list-block-class
carolinan ad1a68d
Merge branch 'trunk' into add/list-block-class
carolinan 71332b4
Try to update tests by adding bock class names
carolinan e9dd993
Revert list-item changes
carolinan 9f7b68f
Remove the experimental selector from block.json
carolinan eb6341c
Add fixture for deprecation v3
carolinan b1d4d0d
Update list class names in test files
carolinan a205584
Update list class names in native test files
carolinan ba7bb78
change experimentalSelector for the list-item block
carolinan 95640c9
Merge branch 'trunk' into add/list-block-class
carolinan a44b0da
Try to fix spacing CS issues in test fixture
carolinan 20fd490
Update blocks-raw-handling.native.js
carolinan ebdd180
Merge branch 'trunk' into add/list-block-class
carolinan f8a55e9
Merge branch 'trunk' into add/list-block-class
carolinan 24032dd
Merge branch 'trunk' into add/list-block-class
carolinan 7d97dad
Merge branch 'trunk' into add/list-block-class
carolinan a9325d3
Merge branch 'trunk' into add/list-block-class
carolinan c2c5a94
Update core-blocks.md
carolinan 69d41a3
Merge branch 'trunk' into add/list-block-class
carolinan 6d71391
Merge branch 'trunk' into add/list-block-class
carolinan a126c43
Remove index.php from the list block
carolinan f4cd398
Merge branch 'trunk' into add/list-block-class
carolinan 18684f1
e2e Specs: Add the block class name to the markup in list.spec.js.
carolinan 70adc20
Merge branch 'trunk' into add/list-block-class
carolinan a242f0a
Re-add the index.php file.
carolinan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting this should have used the selectors API which landed at the end of 2022, rather than the deprecated
__experimentalSelector
.For example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in the process of dusting off an old PR to add color support to the List Item block. I can switch this over to use
selectors
as part of that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for following up on this!