#61351 closed enhancement (fixed)
Simplify the block bindings HTML replacement logic
| Reported by: | santosguillamot | Owned by: | audrasjb |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.6 |
| Component: | Editor | Version: | 6.5 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | Focuses: |
Description
Gutenberg PRs:
- https://github.com/WordPress/gutenberg/pull/61236
- https://github.com/WordPress/gutenberg/pull/61660
Proposal to change the block bindings HTML replacement logic to use a hardcoded list of selectors based on the block and a regex to substitute the inner content.
The existing logic is too complex because the HTML API doesn't support CSS selectors yet and it doesn't have an official way to modify the inner HTML. This makes it difficult to understand, iterate on it and add new functionalities.
As it will be solved in the future once the HTML API is ready, I believe it is better to keep a simple hardcoded version that is easier to understand and iterate on.
Attachments (3)
Change History (10)
This ticket was mentioned in PR #6712 on WordPress/wordpress-develop by @santosguillamot.
2 years ago
#1
- Keywords has-patch added
#2
@
2 years ago
- Component General → Editor
- Keywords commit added
- Milestone Awaiting Review → 6.6
- Version → 6.5
#3
@
2 years ago
Test Report
This report validates that the indicated patch addresses the issue.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/6712
Environment
- OS: macOS 13.6
- Web Server: nginx/1.25.3
- PHP: 8.2.18
- WordPress: 6.6-alpha-57778-src
- Browser: Firefox 127.0b8
- Theme: Twenty Twenty-Four
- Active Plugins: None
Actual Results
- ✅ Paragraph content was successfully replace by the binding in the editor and on the frontend.
- ✅ Heading content was successfully replace by the binding in the editor and on the frontend.
- ✅ Button content was successfully replace by the binding in the editor and on the frontend.
Additional Notes
HTML content use to test the patch :
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"text_custom_field"}}}}} -->
<p>Original content</p>
<!-- /wp:paragraph -->
<!-- wp:heading {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"text_custom_field"}}}}} -->
<h2 class="wp-block-heading">Original content</h2>
<!-- /wp:heading -->
<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"metadata":{"bindings":{"text":{"source":"core/post-meta","args":{"key":"text_custom_field"}}}}} -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://wordpress.org/">Original content</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->
Supplemental Artifacts
See attachments
#4
@
2 years ago
- Owner set to
- Status new → accepted
Alright, looks like we're good to go with the proposed patch. Self assigning for commit.
@audrasjb commented on PR #6712:
2 years ago
#6
committed in https://core.trac.wordpress.org/changeset/58298
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: 61351
Backport of the following PRs: #61236 and #61660
## What?
Change the block bindings HTML replacement logic to use a hardcoded list of selectors based on the block and a regex to substitute the inner content.
Apart from that, it removes some extra breaks that are not needed.
## Why?
The existing logic is too complex because the HTML API doesn't support CSS selectors yet and it doesn't have an official way to modify the inner HTML. This makes it difficult to understand, iterate on it and add new functionalities.
As it will be solved in the future once the HTML API is ready, I believe it is better to keep a simple hardcoded version that is easier to understand and iterate on.
## How?
## Testing Instructions