-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML API: Add select handling #5908
Conversation
083f678
to
68609de
Compare
This comment was marked as outdated.
This comment was marked as outdated.
d53fe6c
to
e2eee29
Compare
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
e2eee29
to
5216819
Compare
5216819
to
6f6c2ae
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
af836be
to
1cd3a08
Compare
1cd3a08
to
0d34838
Compare
0d34838
to
5964758
Compare
87fa7e9
to
81dd7f5
Compare
81dd7f5
to
9d99844
Compare
@dmsnell This is ready for review. |
This reverts commit 9d99844.
* @return bool True if there are nodes on the stack and the top node has | ||
* a matching node_name. | ||
*/ | ||
public function current_node_is( string $node_name ): bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from #6968.
* | ||
* @return bool Whether an element was found. | ||
*/ | ||
private function step_in_head() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should stub out the rest of these step_in_*
methods.
/** | ||
* Checks if the node at the top of the stack matches provided node name. | ||
* | ||
* @example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that this style of example only comes over from the Gutenberg end, and to play well with the WordPress documentation we should follow this pattern
/**
*
* Example:
*
* // Is the current node a text node?
* $stack->current_node_is( '#text' );
*
* // Is the current node a DIV element?
* $stack->current_node_is( 'DIV' );
*/
That is: Example:
, a blank line, and then four spaces to indent the code. This works well with various IDE support thankfully.
* This internal function performs the 'in head' insertion mode | ||
* logic for the generalized WP_HTML_Processor::step() function. | ||
* | ||
* @since 6.7.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can note that this is a stub.
*/ | ||
case '#text': | ||
$this->insert_html_element( $this->state->current_token ); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should perform the same check as we do in IN BODY for null text, as we don't really want to create a new node or pause just for them. that is, if the text node comprises only null bytes, ignore the token.
note that this rule only applies to null bytes directly. it does not apply if the null byte is encoded as a character reference. in that case, the character references �
and �
both decode to the Unicode replacement character �
|
||
/* | ||
* > An end tag whose tag name is "select" | ||
* > A start tag whose tag name is "select" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth it IMO to add the quote from the spec, the "Note"
/*
* > It just gets treated like an end tag.
*/
case '-SELECT': | ||
case '+SELECT': | ||
if ( ! $this->state->stack_of_open_elements->has_element_in_select_scope( 'SELECT' ) ) { | ||
return $this->step(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: Ignore the token
return $this->step(); | ||
} | ||
$this->state->stack_of_open_elements->pop_until( 'SELECT' ); | ||
$this->state->stack_of_open_elements->pop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is superfluous, because pop_until()
pops the requested node.
Pops nodes off of the stack of open elements until one with the given tag name has been popped.
case '+INPUT': | ||
case '+KEYGEN': | ||
case '+TEXTAREA': | ||
// Parse error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This look like it's describing the next line, the if
, but it's just a general remark that this entire case is a parse error. Probably best to move it above in the comment for the cluster of tags.
case '+TEXTAREA': | ||
// Parse error. | ||
if ( ! $this->state->stack_of_open_elements->has_element_in_select_scope( 'SELECT' ) ) { | ||
return $this->step(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: Ignore token.
case '+SCRIPT': | ||
case '+TEMPLATE': | ||
case '-TEMPLATE': | ||
return $this->step_in_head(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: Process the token using the rules for the "in head" insertion mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sirreal I've applied a number of changes including two notables:
- I've added all of the remaining tags to
generate_implied_end_tag()
in order to lighten the burden as we add the remaining tag support. - After noticing a defect in that algorithm (caching
current_element()
) I've updated the logic to be clearer and to ensure that it's always checking the updated current element.
After these changes, three more tests pass that were previously skipped. That could be related to the bug in generate_implied_end_tags()
but I didn't investigate.
As part of work to add more spec support to the HTML API, this patch adds support for the SELECT, OPTION, and OPTGROUP elements, including the requisite support for the IN SELECT insertion mode. Developed in #5908 Discussed in https://core.trac.wordpress.org/ticket/61576 Props dmsnell, jonsurrell. See #61576. git-svn-id: https://develop.svn.wordpress.org/trunk@58677 602fd350-edb4-49c9-b593-d223f7449a82
As part of work to add more spec support to the HTML API, this patch adds support for the SELECT, OPTION, and OPTGROUP elements, including the requisite support for the IN SELECT insertion mode. Developed in WordPress/wordpress-develop#5908 Discussed in https://core.trac.wordpress.org/ticket/61576 Props dmsnell, jonsurrell. See #61576. Built from https://develop.svn.wordpress.org/trunk@58677 git-svn-id: http://core.svn.wordpress.org/trunk@58079 1a063a9b-81f0-0310-95a4-ce76da25c4cd
As part of work to add more spec support to the HTML API, this patch adds support for the SELECT, OPTION, and OPTGROUP elements, including the requisite support for the IN SELECT insertion mode. Developed in WordPress/wordpress-develop#5908 Discussed in https://core.trac.wordpress.org/ticket/61576 Props dmsnell, jonsurrell. See #61576. Built from https://develop.svn.wordpress.org/trunk@58677 git-svn-id: https://core.svn.wordpress.org/trunk@58079 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: Core-61576
Skip fewer of the html5lib-tests:
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.