Skip to content
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

Closed
wants to merge 24 commits into from

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Jan 19, 2024

Trac ticket: Core-61576

A start tag whose tag name is "select"
Reconstruct the active formatting elements, if any.

Insert an HTML element for the token.

Set the frameset-ok flag to "not ok".

If the insertion mode is one of "in table", "in caption", "in table body", "in row", or "in cell", then switch the insertion mode to "in select in table". Otherwise, switch the insertion mode to "in select".

Skip fewer of the html5lib-tests:

 OK, but incomplete, skipped, or risky tests!
-Tests: 607, Assertions: 174, Skipped: 433.
+Tests: 607, Assertions: 184, Skipped: 423.

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.

@sirreal

This comment was marked as outdated.

Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link

github-actions bot commented Feb 2, 2024

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell, dmsnell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@sirreal sirreal force-pushed the html-api/handle-select-tag branch 2 times, most recently from af836be to 1cd3a08 Compare February 2, 2024 15:19
@sirreal sirreal force-pushed the html-api/handle-select-tag branch from 1cd3a08 to 0d34838 Compare June 13, 2024 14:43
@sirreal sirreal force-pushed the html-api/handle-select-tag branch from 0d34838 to 5964758 Compare July 3, 2024 18:53
@sirreal sirreal force-pushed the html-api/handle-select-tag branch from 87fa7e9 to 81dd7f5 Compare July 4, 2024 11:56
@sirreal sirreal force-pushed the html-api/handle-select-tag branch from 81dd7f5 to 9d99844 Compare July 4, 2024 14:25
@sirreal sirreal marked this pull request as ready for review July 4, 2024 14:31
@sirreal
Copy link
Member Author

sirreal commented Jul 4, 2024

@dmsnell This is ready for review.

* @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 {
Copy link
Member Author

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() {
Copy link
Member Author

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.

@sirreal sirreal requested a review from dmsnell July 4, 2024 19:41
/**
* Checks if the node at the top of the stack matches provided node name.
*
* @example
Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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"
Copy link
Member

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();
Copy link
Member

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();
Copy link
Member

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.
Copy link
Member

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();
Copy link
Member

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();
Copy link
Member

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.

Copy link
Member

@dmsnell dmsnell left a 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.

pento pushed a commit that referenced this pull request Jul 5, 2024
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
@dmsnell
Copy link
Member

dmsnell commented Jul 5, 2024

Merged in [58677]
c1154f9

@dmsnell dmsnell closed this Jul 5, 2024
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jul 5, 2024
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
@dmsnell dmsnell deleted the html-api/handle-select-tag branch July 5, 2024 00:54
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this pull request Jul 5, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants