Skip to content

[Data Liberation] Block markup consumers and producers - #2121

Merged
adamziel merged 3 commits into
trunkfrom
add-more-html-plumbing
Jan 10, 2025
Merged

[Data Liberation] Block markup consumers and producers#2121
adamziel merged 3 commits into
trunkfrom
add-more-html-plumbing

Conversation

@adamziel

@adamziel adamziel commented Jan 9, 2025

Copy link
Copy Markdown
Collaborator

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant