-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 table support #6040
Conversation
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. |
8e69884
to
7b92ef5
Compare
e0787ef
to
759ca17
Compare
This is an algorithm defined in the standard: https://html.spec.whatwg.org/multipage/parsing.html#clear-the-list-of-active-formatting-elements-up-to-the-last-marker
759ca17
to
9c59014
Compare
058e995
to
2ded522
Compare
Use the method implemented in WordPress#6982 to avoid duplicating the same functionality.
Instead of bailing directly, call the appropriate step_in_ method.
The spec inserts some elements not present in the DOM to preserve proper table structure. Add explanatory comment.
The spec inserts some elements not present in the DOM to preserve proper table structure. Add explanatory comment.
This reverts commit d14eaf3.
! $this->state->stack_of_open_elements->has_element_in_table_scope( 'THEAD' ) && | ||
! $this->state->stack_of_open_elements->has_element_in_table_scope( 'TFOOT' ) | ||
) { | ||
// @todo Indicate a parse error once it's possible. |
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.
just curious about this, because these elements are implicitly created on +TABLE
, so I think the only case we could get here is with a TEMPLATE
<table>
<td><template>This </table> does not close the outer one</template>
</table>
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 just following the spec (quoted below). I'm reluctant to deviate from the spec in all but the most obvious places. There are many places the switch modes and reprocess tokens or process tokens following the rules for other modes.
A character token, if the current node is table, tbody, template, tfoot, thead, or tr element
Let the pending table character tokens be an empty list of tokens.Let the original insertion mode be the current insertion mode.
Switch the insertion mode to "in table text" and reprocess the token.
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.
there was no hint of asking you to deviate from the spec; all I was doing was observing an interesting oddity since the only elements we're checking are ones that should always be open. I think that TEMPLATE
is the only exception. this was just exploring the rules.
if this turns out to be true, it might be possible one day to verify and take advantage of. for now, all it did was seem odd when I saw it, and then I realized there's an escape hatch in almost all of these situations - the TEMPLATE
element.
Assertions from the spec are explicitly optional in implementation. Remove the assertion, it's checking an invariant condition.
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 fixed two logic issues:
- in
IN CELL
we have to check if the current node has the same name as the matched token, but we were only checking that it had a name at all. - in
IN TABLE BODY
for-TBODY, …
we needed to clear to table body context.
After our short discussion about it I went ahead with insert_virtual_node()
because I want that to have a bookmark, and I think it might be important later to add things like namespace and whether it's virtual.
I've made comment and other minor changes, which can all be reverted if you think it's best as it was before.
@@ -765,6 +765,7 @@ public function expects_closer( $node = null ): ?bool { | |||
} | |||
|
|||
return ! ( | |||
( $node->has_self_closing_flag ?? false ) || |
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.
Interestingly, @sirreal, this is no longer required, since we moved to processing the event queue. I'm leaving it in for now, though, while pondering the later change which avoids immediately popping the FORM off the stack of open elements.
@@ -2347,10 +2354,12 @@ private function step_in_table(): bool { | |||
) { | |||
return $this->step(); | |||
} | |||
|
|||
// This FORM is special because it immediately closes and cannot have other children. | |||
$this->state->current_token->has_self_closing_flag = 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.
This is where I'm pondering.
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.
What's the motivation for doing it this way instead of adding and popping right here?
The "> …" quoting omitted part of the quoted spec. Include the complete spec in the quoting.
There's an error in the new form test with the change to auto-close the form where the form closer is not visited by diff --git before/src/wp-includes/html-api/class-wp-html-processor.php after/src/wp-includes/html-api/class-wp-html-processor.php
index 1e6a18389b..0d1c7c1496 100644
--- before/src/wp-includes/html-api/class-wp-html-processor.php
+++ after/src/wp-includes/html-api/class-wp-html-processor.php
@@ -2356,10 +2356,9 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
}
// This FORM is special because it immediately closes and cannot have other children.
- $this->state->current_token->has_self_closing_flag = true;
-
$this->insert_html_element( $this->state->current_token );
$this->state->form_element = $this->state->current_token;
+ $this->state->stack_of_open_elements->pop();
return true;
}
I'll push that change and tests should be passing again. It's effectively reverting part of your updates so happy to discuss further. |
@dmsnell The changes you've pushed look good, thanks for catching a couple of bugs and I do like the method for creating virtual nodes. The last remaining thing is to sort out the FORM element in table insertion mode that's immediately popped. |
I was considering this because I wanted the code to function as the void tags function, but I can't figure out what's wrong. Along the way I found some bugs in |
As part of work to add more spec support to the HTML API, this patch adds support for various table-related insertion modes. This includes support for tables, table rows, table cells, table column groups, etc... Developed in #6040 Discussed in https://core.trac.wordpress.org/ticket/61576 Props: dmsnell, jonsurrell. See #61576. git-svn-id: https://develop.svn.wordpress.org/trunk@58806 602fd350-edb4-49c9-b593-d223f7449a82
As part of work to add more spec support to the HTML API, this patch adds support for various table-related insertion modes. This includes support for tables, table rows, table cells, table column groups, etc... Developed in WordPress/wordpress-develop#6040 Discussed in https://core.trac.wordpress.org/ticket/61576 Props: dmsnell, jonsurrell. See #61576. Built from https://develop.svn.wordpress.org/trunk@58806 git-svn-id: http://core.svn.wordpress.org/trunk@58202 1a063a9b-81f0-0310-95a4-ce76da25c4cd
As part of work to add more spec support to the HTML API, this patch adds support for various table-related insertion modes. This includes support for tables, table rows, table cells, table column groups, etc... Developed in WordPress/wordpress-develop#6040 Discussed in https://core.trac.wordpress.org/ticket/61576 Props: dmsnell, jonsurrell. See #61576. Built from https://develop.svn.wordpress.org/trunk@58806 git-svn-id: https://core.svn.wordpress.org/trunk@58202 1a063a9b-81f0-0310-95a4-ce76da25c4cd
As part of work to add more spec support to the HTML API, this patch adds support for various table-related insertion modes. This includes support for tables, table rows, table cells, table column groups, etc... Developed in WordPress#6040 Discussed in https://core.trac.wordpress.org/ticket/61576 Props: dmsnell, jonsurrell. See #61576. git-svn-id: https://develop.svn.wordpress.org/trunk@58806 602fd350-edb4-49c9-b593-d223f7449a82
Trac ticket: Core-61576
Add support for table elements:
Not all necessary insertion modes are implemented in this PR, so e.g. "in caption" and "in select in table" modes are not implemented in this PR.
HTML5-lib test change (
./vendor/bin/phpunit --group html-api-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.