gutenberg
gutenberg copied to clipboard
Block Library: Refactor core blocks to use HTML Tag Processor
What?
The full proposal for the new HTM Tag Processor API is available at https://make.wordpress.org/core/2022/08/19/a-new-system-for-simply-and-reliably-updating-html-attributes/.
Why?
This branch presents the usage of the new HTML Tag Processor API introduced by @adamziel and @dmsnell in https://github.com/WordPress/gutenberg/pull/42485.
How?
Updated core blocks:
- Cover
- Gallery
- Image
- Site Logo
Testing Instructions
All updated core blocks should work as before.
I rebase this branch with trunk
. Refactored code to use the new class name WP_HTML_Tag_Processor
. One of the core blocks Post Featured Image got refactored and it no longer is necessary to use Tag Processor there.
I wrapped all values passed to set_attribute
with esc_attr
to present how this would look in practice if we leave it up to developers.
Esc_attr shouldn’t be needed thanks to https://github.com/WordPress/gutenberg/pull/44447. Let’s remove it to avoid escaping the value twice.
Esc_attr shouldn’t be needed thanks to #44447. Let’s remove it to avoid escaping the value twice.
Nice, it still might be necessary to use some sanitization in some cases so we need to have a good documentation that covers all possible scenarios.
@adamziel and @dmsnell, I think this PR depends on how https://github.com/WordPress/gutenberg/pull/44447 ends up handling escaping attributes. It would be great if you could bring it to the finish line. 1983b8f removes esc_attr
usage, so if we need to add it back, we only need to remove this commit.
If we want these in WordPress 6.2 we should hurry and merge them, otherwise I don't think it matters if we merge sooner or later.
I refreshed this PR to use the latest API. It doesn't matter if we include it in WordPress 6.2. Actually, it's probably better to test it in the plugin first.
Flaky tests detected in 9bb0a03c79edc589290f171bba851ead654020ed. Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4231586927 📝 Reported issues:
- #39787 in
specs/editor/various/multi-block-selection.test.js
Testing
Cover block
✅ Minimum height style applied correctly

Image block
✅ Aria label and target applied correctly

Social Icon
✅ Still properly handles rel
and target
attributes

Still looking good 👍
I'd like to know if hurry was the only reason the regex for removing the link from the site logo was left as is? That regex was what was flagged as incorrect and used as one of the reasons for including the tag processor in the first place :). If that is the only reason, that is not a problem! No complaints. I am only asking to learn if there was another reason or if I can continue with replacing the regex.
I'd like to know if hurry was the only reason the regex for removing the link from the site logo was left as is?
HTML Tag Processor doesn't support removing HTML tags as of today, it only allows operations on HTML attributes.
Aha! Thank you @gziolo. We need to wait then.