-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[Heading block] Add a wp-block-heading CSS class #42122
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2e30c81
Add a wp-block-heading CSS class and adjust the test stubs
adamziel 6b20e3e
Only apply the classname updates to the H1-H6 tags
adamziel 2eaf660
Merge branch 'trunk' into add-css-class-to-heading-blocks
adamziel 228efe1
Don't try to add the class name to more than one tag
adamziel 3b4939c
Adjust the test snapshots
adamziel 27b767a
Update package-lock.json
adamziel c3d6ad3
Refresh snapshots and package-lock.json
adamziel ab0515f
Adjust native tests snapshot
adamziel 8b4cf87
Adjust PHP unit test to WP_HTML_Tag_Processor output
adamziel db3a732
Rebuild docs
adamziel 3389bba
Adjust mobile snapshots
adamziel 33bc984
Adjust the e2e test snapshot
adamziel 0f7b219
Update e2e test snapshots
adamziel 7e7dfec
Adjust playwright test specs
adamziel 17a83c2
Lint
adamziel 764249a
Lint
adamziel 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ | |
| "supports": { | ||
| "align": [ "wide", "full" ], | ||
| "anchor": true, | ||
| "className": false, | ||
| "className": true, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this change might also mean that the className is being serialized to post content. Was that intentional?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #42122 (comment) |
||
| "color": { | ||
| "gradients": true, | ||
| "link": true, | ||
|
|
||
This file contains hidden or 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,51 @@ | ||
| <?php | ||
| /** | ||
| * Appending the wp-block-heading to before rendering the stored `core/heading` block contents. | ||
| * | ||
| * @package WordPress | ||
| */ | ||
|
|
||
| /** | ||
| * Adds a wp-block-heading class to the heading block content. | ||
| * | ||
| * For example, the following block content: | ||
| * <h2 class="align-left">Hello World</h2> | ||
| * | ||
| * Would be transformed to: | ||
| * <h2 class="align-left wp-block-heading">Hello World</h2> | ||
adamziel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * @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_heading_render( $attributes, $content ) { | ||
| if ( ! $content ) { | ||
| return $content; | ||
| } | ||
|
|
||
| $p = new WP_HTML_Tag_Processor( $content ); | ||
|
|
||
| $header_tags = array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ); | ||
| while ( $p->next_tag() ) { | ||
| if ( in_array( $p->get_tag(), $header_tags, true ) ) { | ||
| $p->add_class( 'wp-block-heading' ); | ||
adamziel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| return $p->get_updated_html(); | ||
| } | ||
adamziel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Registers the `core/heading` block on server. | ||
| */ | ||
| function register_block_core_heading() { | ||
| register_block_type_from_metadata( | ||
| __DIR__ . '/heading', | ||
| array( | ||
| 'render_callback' => 'block_core_heading_render', | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| add_action( 'init', 'register_block_core_heading' ); | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.