alleyinteractive / wp-match-blocks

Match WordPress blocks in the given content.
GNU General Public License v2.0
7 stars 1 forks source link

Match 'classic' blocks as non-empty blocks #11

Closed dlh01 closed 1 year ago

dlh01 commented 1 year ago

Summary

Blocks named null have been considered "empty," but "classic" blocks containing freeform HTML are also named null. This behavior is unexpected during content migrations involving non-block content, since the default behavior of match_blocks() on such content can return an empty set, leading to data loss.

With this change in this PR, blocks are considered empty if they are named null and contain only space in their inner HTML. This change has the potential to cause a different kind of confusion: Given a piece of HTML without any block delimiters, the default behavior of match_blocks() will now be to return a set of one block instead of an empty set.

I've chosen to proceed with the change despite this unintuitive result because the behavior of match_blocks() has tended to act as a reducer of the results returned by WP_Block_Parser, which also returns one block for the same HTML rather than eliminating the content from the parsed result.

Notes for reviewers

None.

Changelog entries

Added

Changed

Deprecated

Removed

Fixed

Security