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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b867b58
Implement SELECT and related tags handling
sirreal Jan 19, 2024
9245930
Remove SELECT from unsupported elements test
sirreal Jul 3, 2024
267a27b
Remove SELECT scope optgroup/option tests
sirreal Jul 3, 2024
b0475fb
Remove SELECT, OPTION, OPTGROUP from unsupported tags
sirreal Jul 3, 2024
1944b66
Remove OPTION,OPTGROUP from gen implied end tags unsupported test
sirreal Jul 3, 2024
8d4b4df
Add OPTION, OPTGROUP to implied end tags
sirreal Jul 4, 2024
1404119
Update step_in_select since tag
sirreal Jul 4, 2024
dc0bbb9
Update since tags on in_select_scope
sirreal Jul 4, 2024
9d99844
Implement in_select_scope via …in_specific_scope
sirreal Jul 4, 2024
3085405
Revert "Implement in_select_scope via …in_specific_scope"
sirreal Jul 4, 2024
e095c62
Add current_node_is method
sirreal Jul 4, 2024
4026493
Merge branch 'html-api/add-current-node-is' into html-api/handle-sele…
sirreal Jul 4, 2024
76c899a
Add text, comment, doctype handling
sirreal Jul 4, 2024
52fd8e5
Handle +HTML case
sirreal Jul 4, 2024
6a10eb0
Update several cases to use current_node_is
sirreal Jul 4, 2024
8b3a9e4
Simplify -OPTGROUP handling implementation
sirreal Jul 4, 2024
87c6596
Add input,keygen,textarea,script,template handling
sirreal Jul 4, 2024
d464330
Add "anything else" handling
sirreal Jul 4, 2024
ddbd676
Add step_in_head stub
sirreal Jul 4, 2024
f6d686d
Multi-line comments should be block comments
sirreal Jul 4, 2024
783cef6
fixup! Update several cases to use current_node_is
sirreal Jul 4, 2024
3222275
Fix step_in_head documentation block
sirreal Jul 4, 2024
eb126e8
Merge branch 'trunk' into html-api/handle-select-tag
dmsnell Jul 4, 2024
f2e1d03
Apply feedback requests.
dmsnell Jul 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions src/wp-includes/html-api/class-wp-html-open-elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@ public function current_node_is( string $identity ): bool {
/**
* Returns whether an element is in a specific scope.
*
* ## HTML Support
*
* This function skips checking for the termination list because there
* are no supported elements which appear in the termination list.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#has-an-element-in-the-specific-scope
Expand Down Expand Up @@ -311,19 +306,38 @@ public function has_element_in_table_scope( $tag_name ) {
/**
* Returns whether a particular element is in select scope.
*
* @since 6.4.0
* This test differs from the others like it, in that its rules are inverted.
* Instead of arriving at a match when one of any tag in a termination group
* is reached, this one terminates if any other tag is reached.
*
* @see https://html.spec.whatwg.org/#has-an-element-in-select-scope
* > The stack of open elements is said to have a particular element in select scope when it has
* > that element in the specific scope consisting of all element types except the following:
* > - optgroup in the HTML namespace
* > - option in the HTML namespace
*
* @throws WP_HTML_Unsupported_Exception Always until this function is implemented.
* @since 6.4.0 Stub implementation (throws).
* @since 6.7.0 Full implementation.
*
* @see https://html.spec.whatwg.org/#has-an-element-in-select-scope
*
* @param string $tag_name Name of tag to check.
* @return bool Whether given element is in scope.
* @return bool Whether the given element is in SELECT scope.
*/
public function has_element_in_select_scope( $tag_name ) {
throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on select scope.' );
foreach ( $this->walk_up() as $node ) {
if ( $node->node_name === $tag_name ) {
return true;
}

return false; // The linter requires this unreachable code until the function is implemented and can return.
if (
'OPTION' !== $node->node_name &&
'OPTGROUP' !== $node->node_name
) {
return false;
}
}

return false;
}

/**
Expand Down
Loading
Loading