Skip to content

Commit 6d4a6ed

Browse files
committed
Add note linking parse_blocks and block_scanner
1 parent c118e38 commit 6d4a6ed

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/wp-includes/blocks.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,17 @@ function render_block( $parsed_block ) {
23622362
/**
23632363
* Parses blocks out of a content string.
23642364
*
2365+
* Given an HTML document, this function fully-parses block content, producing
2366+
* a tree of blocks and their contents, as well as top-level non-block content,
2367+
* which will appear as a block with no `blockName`.
2368+
*
2369+
* This function can be memory heavy for certain documents, particularly those
2370+
* with deeply-nested blocks or blocks with extensive attribute values. Further,
2371+
* this function must parse an entire document in one atomic operation.
2372+
*
2373+
* If the entire parsed document is not necessary, consider using {@see WP_Block_Scanner}
2374+
* instead, as it provides a streaming and low-overhead interface for finding blocks.
2375+
*
23652376
* @since 5.0.0
23662377
*
23672378
* @param string $content Post content.

src/wp-includes/class-wp-block-scanner.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*
1616
* For usage, jump straight to {@see self::next_delimiter}.
1717
*
18+
* If it’s necessary to end up with a fully-parsed document anyway,
19+
* consider using {@see parse_blocks()} instead.
20+
*
1821
* @todo Add wildcard matching to namespace and name in ::opens_block(), ::is_block_type, etc…
1922
* @todo Is "freeform" the best name since it can also appear inside blocks? Maybe "html" or "text" or "non-block content".
2023
* @todo Add optimized lookup for blocks of a known name

0 commit comments

Comments
 (0)