Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Data Liberation] Block markup consumers and producers #2121

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Jan 9, 2025

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:

$block_markup = <<<BLOCKS
<!-- wp:paragraph -->
<p>Hello <b>world</b>!</p>
<!-- /wp:paragraph -->
BLOCKS;

$metadata =  array(
     'post_title' => array( 'My first post' ),
);

And this:

<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.

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

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.
@adamziel adamziel merged commit 3443569 into trunk Jan 10, 2025
10 checks passed
@adamziel adamziel deleted the add-more-html-plumbing branch January 10, 2025 00:35
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant