Make WordPress Core

Opened 6 weeks ago

Last modified 6 weeks ago

#61401 new feature request

Blocks: Efficiently find and traverse blocks in a document.

Reported by: dmsnell's profile dmsnell Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch
Focuses: Cc:


The existing block parser reliably parses blocks, but it's also a heavy operation, involving a full parse of the entire document, the construction of a full block tree which includes multiple copies of different spans of the source content, and the JSON-parsing of every span of block attributes.

In many situations it's only necessary to find specific blocks within a document, or find where they start or end, or build a map of document structure without needing the full parse.

WordPress should provide a reliable and efficient way to traverse the Blocks in an HTML document in a streaming manner.

Change History (1)

This ticket was mentioned in PR #6760 on WordPress/wordpress-develop by @dmsnell.

6 weeks ago

  • Keywords has-patch added

Trac ticket: Core-61401

In this patch two new functions are introduced for the purpose of returning a PCRE pattern that can be used to quickly and efficiently find blocks within an HTML document without having to parse the entire document and without building a full block tree.

These new functions enable more efficient processing for work that only needs to examine document structure or know a few things about a document without knowing everything, including but not limited to:

  • Finding the URL of the first image block in a document.
  • Inserting hooked blocks.
  • Analyzing block counts.
Note: See TracTickets for help on using tickets.