Skip to content

Commit

Permalink
HTML API: Add TABLE support in HTML Processor.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dmsnell committed Jul 24, 2024
1 parent 881ac87 commit 5351cd2
Show file tree
Hide file tree
Showing 4 changed files with 677 additions and 17 deletions.
74 changes: 74 additions & 0 deletions src/wp-includes/html-api/class-wp-html-open-elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,80 @@ public function after_element_pop( WP_HTML_Token $item ): void {
}
}

/**
* Clear the stack back to a table context.
*
* > When the steps above require the UA to clear the stack back to a table context, it means
* > that the UA must, while the current node is not a table, template, or html element, pop
* > elements from the stack of open elements.
*
* @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-stack-back-to-a-table-context
*
* @since 6.7.0
*/
public function clear_to_table_context(): void {
foreach ( $this->walk_up() as $item ) {
if (
'TABLE' === $item->node_name ||
'TEMPLATE' === $item->node_name ||
'HTML' === $item->node_name
) {
break;
}
$this->pop();
}
}

/**
* Clear the stack back to a table body context.
*
* > When the steps above require the UA to clear the stack back to a table body context, it
* > means that the UA must, while the current node is not a tbody, tfoot, thead, template, or
* > html element, pop elements from the stack of open elements.
*
* @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-stack-back-to-a-table-body-context
*
* @since 6.7.0
*/
public function clear_to_table_body_context(): void {
foreach ( $this->walk_up() as $item ) {
if (
'TBODY' === $item->node_name ||
'TFOOT' === $item->node_name ||
'THEAD' === $item->node_name ||
'TEMPLATE' === $item->node_name ||
'HTML' === $item->node_name
) {
break;
}
$this->pop();
}
}

/**
* Clear the stack back to a table row context.
*
* > When the steps above require the UA to clear the stack back to a table row context, it
* > means that the UA must, while the current node is not a tr, template, or html element, pop
* > elements from the stack of open elements.
*
* @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-stack-back-to-a-table-row-context
*
* @since 6.7.0
*/
public function clear_to_table_row_context(): void {
foreach ( $this->walk_up() as $item ) {
if (
'TR' === $item->node_name ||
'TEMPLATE' === $item->node_name ||
'HTML' === $item->node_name
) {
break;
}
$this->pop();
}
}

/**
* Wakeup magic method.
*
Expand Down
Loading

0 comments on commit 5351cd2

Please sign in to comment.