Skip to content

Replace logic inBlock.contentSource if WP_Block_Parser_Block ever supports retrieving original HTML source #2346

@leoloso

Description

@leoloso

Field Block.contentSource regenerates the block's original HTML content. It accomplishes this by calling PHP function serialize_block in createBlock.

However, this value will not be exactly the same as the one stored in the DB (i.e. the one generated via JavaScript/Gutenberg). This is because:

  • the default attributes (eg: an empty array) should not be included, however serialize_block does not remove them
  • attributes stored inside the innerHTML (eg: the HTML for the paragraph block) are also stored within the attributes (and thus this string is duplicated!)

A better solution would be to retrieve the HTML content as is, already when parsing the blocks in class
WP_Block_Parser_Block (see wp-includes/class-wp-block-parser.php). But this is currently not supported!

TODO: If WP_Block_Parser_Block ever retrieves the original HTML source, then use this logic to resolve Block.contentSource.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions