-
Couldn't load subscription status.
- Fork 3.1k
Blocks: Introduce WP_Block_Processor for efficiently parsing blocks.
#9105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
d872db2 to
6d4a6ed
Compare
c3dc0eb to
0f3d8cf
Compare
tests/phpunit/tests/block-scanner/wpBlockScanner-BlockProcessing.php
Outdated
Show resolved
Hide resolved
82c693a to
5f99617
Compare
|
@gziolo something I was thinking about on my walk this morning was an idea I’ve ignored for a while, but maybe is worth it here: by default we skip freeform HTML content. the way we could signal to visit it is not with a boolean attribute, but using a special block type in // visit all explicit block delimiters
$scanner->next_delimiter();
// visit all block delimiters plus freeform blocks.
$scanner->next_delimiter( '*' );
// visit all freeform blocks: a possible special token meaning “no explicit block”
$scanner->next_delimiter( '#freeform' );
// visit all HTML spans, including `innerHTML`
$scanner->next_token();this would collapse the difference between I will try and explore this angle. |
fa33ff1 to
53e2769
Compare
That's interesting. It creates a nice logical separation between higher-level
We have this concept of freeform content handler in JavaScript which you can even modify with |
That’s something I wish had been more hard-coded and less extensible, based on my work on the two-stage block parsing and loading inside the block editor, both in WordPress and in Tumblr. But I guess JS is different because we have to load something into the editor, whereas on the server a non-block can remain not a block. Since yesterday I’ve been using
When I left off last night I was working on my Hopefully that clears up all of the remaining issues. |
98e19bc to
853e3a6
Compare
|
This has been updated significantly to clarify the interface and to merge the block scanner and block processor into one. It would be really helpful to have review over the public methods, their docblocks, and the usage in the test suite. I plan on going back to update the class/module docblock with more substantial general guidance for the class. Also I plan on doing a separate type annotation pass, so please disregard any comments currently on type annotations. |
853e3a6 to
4b027f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple nits
4b027f3 to
3fee490
Compare
WP_Block_Scanner for efficiently parsing blocks.WP_Block_Processor for efficiently parsing blocks.
|
With significant haste in the eleventh hour I have finished making some major changes to this proposal:
Personally I’m quite happy with this revision and I thank you all for your input on this. I think it’s in a much more coherent and usable state now. At this point I believe it’s ready for final review and merge, though I think it would be best only to block merging now for design issues with the class, the methods, the things which must be maintained ad infinitum. For other issues, I would prefer if we can address them during the beta phase after merging. Of course, I invite all feedback and will address things if I can in a timely manner, but right now I would love to see this out there in |
…ordPress#9105) The Block Processor follows the HTML API in providing a streaming, near-zero-overhead, lazy, re-entrant parser for traversing block structure. This class provides an alternate interface to `parse_blocks()` which is more amenable to a number of common server-side operations on posts, such as: - Generating an excerpt from only the first N blocks in a post. - Determining which block types are present in a post. - Determining which posts contain a block of a given type. - Generating block supports content for a post. - Modifying a single block, or only blocks of a given kind in a post. Co-authored-by: Sören Wünsch <[email protected]> Co-authored-by: Tom J Nowell <[email protected]> Co-authored-by: Weston Ruter <[email protected]> Co-authored-by: Jon Surrell <[email protected]> Co-authored-by: Greg Ziółkowski <[email protected]> Github-PR: 9105 Github-PR-URL: WordPress#9105 Trac-Ticket: 61401 Trac-Ticket-URL: https://core.trac.wordpress.org/ticket/61401
4625a42 to
549ee7f
Compare
The Block Processor follows the HTML API in providing a streaming, near-zero-overhead, lazy, re-entrant parser for traversing block structure. This class provides an alternate interface to `parse_blocks()` which is more amenable to a number of common server-side operations on posts, especially those needing to operate on only a part of a full post. Developed in #9105 Discussed in https://core.trac.wordpress.org/ticket/61401 Props dmsnell, gziolo, jonsurrell, soean, tjnowell, westonruter. Fixes #61401. git-svn-id: https://develop.svn.wordpress.org/trunk@60939 602fd350-edb4-49c9-b593-d223f7449a82
The Block Processor follows the HTML API in providing a streaming, near-zero-overhead, lazy, re-entrant parser for traversing block structure. This class provides an alternate interface to `parse_blocks()` which is more amenable to a number of common server-side operations on posts, especially those needing to operate on only a part of a full post. Developed in WordPress/wordpress-develop#9105 Discussed in https://core.trac.wordpress.org/ticket/61401 Props dmsnell, gziolo, jonsurrell, soean, tjnowell, westonruter. Fixes #61401. Built from https://develop.svn.wordpress.org/trunk@60939 git-svn-id: http://core.svn.wordpress.org/trunk@60275 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The Block Processor follows the HTML API in providing a streaming, near-zero-overhead, lazy, re-entrant parser for traversing block structure. This class provides an alternate interface to `parse_blocks()` which is more amenable to a number of common server-side operations on posts, especially those needing to operate on only a part of a full post. Developed in WordPress/wordpress-develop#9105 Discussed in https://core.trac.wordpress.org/ticket/61401 Props dmsnell, gziolo, jonsurrell, soean, tjnowell, westonruter. Fixes #61401. Built from https://develop.svn.wordpress.org/trunk@60939 git-svn-id: https://core.svn.wordpress.org/trunk@60275 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Replaces #6760
Trac ticket: Core-61401
See: (
#9105),#9841,#9842-> #10291,#9843-> #10292Todo
parse_blocks()docs and explain when to use which interfaceDescription
The Block Scanner follows the HTML API in providing a streaming,
near-zero-overhead, lazy, re-entrant parser for traversing block
structure. This class provides an alternate interface to
parse_blocks()which is more amenable to a number of commonserver-side operations on posts, such as:
Planned refactors
traverse_and_serialize_blocks()/ block hooks