WIP: Parser: Add tokens for inner blocks in inner HTML #11309
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivated by #8760
Necessary for #10463, #10108
Abstract
Add tokens in
innerHTML
of parsedpost_content
indicating where each of a block'sinnerBlocks
came from. e.g.innerHTML: "Before <!-- {0} --> Middle <!-- {1} --> After"
Status
Summary
Inner blocks, or nested blocks, or blocks-within-blocks, can exist in Gutenberg posts. They are serialized in
post_content
in-place as normal blocks which exist in between another block's comment delimiters.The way this gets parsed leaves us in a quandary: we cannot reconstruct the original
post_content
after parsing because we lose the origin location information for each inner block since they are only passed as an array of inner blocks.At this point we have parsed the blocks and prepared them for attaching into the JavaScript block code that interprets them but we have lost our reverse transformation.
In this PR I'd like to introduce a new mechanism which should only marginally break existing functionality but which will enable us to go back and forth isomorphically between the
post_content
and first stage of parsing. If we can tear apart a Gutenberg post and reassemble then it will let us to structurally-informed processing of the posts without needing to be aware of all the block JavaScript.The proposed mechanism is a form of tombstone or token inserted into
innerHTML
where theinnerBlocks
were found.The token is a normal HTML comment of trivial structure which (if accidentally not removed before rendering) should not display in the rendered page, which should be trivial to substitute with a RegEx-based replacement, and which should remain straightforward for plugin authors and translators to deal with.
These tokens won't exist in
post_content
and they will be stripped before rendering the page. They exist only to restore isomorphism to the parser/printer pair.