You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Data Liberation] Block markup consumers and producers (#2121)
A part of #1894
Introduces a standardized API for converting between static data formats
and blocks+metadata.
* The `data format -> blocks+metadata` operation is represented by the
WP_Data_Format_Consumer interface
* The `blocks+metadata -> data format` operation is represented by the
WP_Data_Format_Producer interface
This PR also ships a few initial consumers and producers:
* `WP_Annotated_Block_Markup_Consumer` – for consuming static block
markup with `<meta>` tags.
* `WP_Markup_Processor_Consumer` – for consuming an HTML/XHTML markup
processor instance. It handles just the regular HTML/XHTML markup, not
block markup.
* `WP_Annotated_Block_Markup_Producer` – for serializing block markup +
metadata array as block markup with `<meta>` tags
## Example
The two-way conversion pipeline shipped in this PR goes between this:
```php
$block_markup = <<<BLOCKS
<!-- wp:paragraph -->
<p>Hello <b>world</b>!</p>
<!-- /wp:paragraph -->
BLOCKS;
$metadata = array(
'post_title' => array( 'My first post' ),
);
```
And this:
```html
<meta name="post_title" content="My first post">
<!-- wp:paragraph -->
<p>Hello <b>world</b>!</p>
<!-- /wp:paragraph -->
```
## Other changes
This PR also ships the block parser from WordPress core to enable
running unit tests – we need to call `parse_blocks()` now.
## Testing
The code isn't used anywhere yet – just rely on the CI.
0 commit comments