Block Parser: Start building a unified block/HTML parser. #6381
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.
Many blocks are starting to be modified with the HTML API. Given that the HTML API will already be parsing block content, and also that it reads HTML comments along the way, it might make sense to combine the multiple passes of block and HTML parsing into one.
Builds on ideas explored in #5705
Combining the parsers could:
introduce new before and after hooks where blocks can be inserted. this could introduce a new block hooks mechanism which doesn't require parsing and traversing the block structure, but can "tag along" with the normal process.
provide new insight and context into the block parsing, such as knowing where in the HTML a block is, or where, in a block tree the given HTML is.
improve efficiency by lazily-decoding the JSON attributes and by reusing the input string rather than breaking it up into many substring copies.
replace block bindings as blocks are parsed, avoiding yet another parsing pass.
process Interactivity API directives as the document is parsed, linearly, and in a streaming fashion. this would avoid the need to run the Server Directive Processor over the entire document after it's already been parsed.
post-process block output to run global policies concerning attribute values and allowable HTML markup.
It could slow some things down, however, which otherwise wouldn't require the block and HTML parsing. For example, the block parser is fast, if memory hungry. Parsing HTML along the way could slow it down.