Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Trac ticket: Core-60170
Companion port into Gutenberg: WordPress/gutenberg#58107 (contains additional porting code)
This PR provides full tokenization scanning of an HTML document. This is being added into the Tag Processor and will be a necessary component for a number of related changes to the HTML API:
Enables syntax-aware processing such as
wp_truncate_html()[gist]Replaces/incorporates chunked/extended processing in #5050
Replaces/incorporates stopping at comments in dmsnell#7
Provides critical functionality for inner/outer getter/setter in [dmsnell#10, #4965]
Depends on #5721 ✅
Depends on #5725 ✅
Todo
$this->bytes_already_parsedassignments and make sure they are proper. I think half of them are one off.MATCHED_TAG | TEXT_NODEandINCOMPLETE | COMPLETE, which could simplify some logic that's spread inifstatements.<!--->.>, not the closing]]>or the closing?>. So we can find all HTML comments, and then determine if they would have been a CDATA or PI Node if HTML supported those.<?for-each?>from<--for-each-->.Design Changes
In this change we're introducing two features stemming from two internal changes:
next_token()provides the ability to scan every token in the HTML stream.The internal changes powering this are:
For example, when encountering an HTML comment the parser will track the following token information:
Not every token will have a text region, but it's important to track the entire token and any text region because similar tokens may have different syntax. For example, an invalid comment is still a comment.
This holds for tokens whose entire content is text, such as with the
#textnode.Special HTML tags have modifiable text and that isn't part of
.textConentor.innerText. For example, theTITLEelement contains no HTML inside of it and everything is plaintext and its contents don't appear in the page. The same is true forTEXTAREAandSCRIPTandSTYLEand a few more elements.Scanning tokens
In order to keep the
next_tag()interface and use clear, it is left unchanged. For operations needing access to the token stream, there is no built-in query mechanism and querying ought to be performed inside anext_token()loop.get_token_type()indicates what kind of token is currently matched,get_token_name()returns something that more closely matches what a DOM API would return, andget_modifiable_text()returns the modifiable text if available.TODO
next_token()method to scan each token.SCRIPT,STYLE,TITLE,TEXTAREA, etc…SCRIPTtags and other tags with special closing rules. These are currently handled by skipping to the end of the element when finding the starting tag, but this has introduced a few challenges and bugs (for example, the Tag Processor fails to stop at a<title>tag if the document ends before the</title>closer is found).rewind()method to reverse to the start of the document.