Make WordPress Core


Ignore:
Timestamp:
07/24/2024 06:39:46 PM (11 months ago)
Author:
dmsnell
Message:

HTML API: Add TABLE support in HTML Processor.

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 https://github.com/wordpress/wordpress-develop/pull/6040
Discussed in https://core.trac.wordpress.org/ticket/61576

Props: dmsnell, jonsurrell.
See #61576.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-open-elements.php

    r58779 r58806  
    722722
    723723    /**
     724     * Clear the stack back to a table context.
     725     *
     726     * > When the steps above require the UA to clear the stack back to a table context, it means
     727     * > that the UA must, while the current node is not a table, template, or html element, pop
     728     * > elements from the stack of open elements.
     729     *
     730     * @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-stack-back-to-a-table-context
     731     *
     732     * @since 6.7.0
     733     */
     734    public function clear_to_table_context(): void {
     735        foreach ( $this->walk_up() as $item ) {
     736            if (
     737                'TABLE' === $item->node_name ||
     738                'TEMPLATE' === $item->node_name ||
     739                'HTML' === $item->node_name
     740            ) {
     741                break;
     742            }
     743            $this->pop();
     744        }
     745    }
     746
     747    /**
     748     * Clear the stack back to a table body context.
     749     *
     750     * > When the steps above require the UA to clear the stack back to a table body context, it
     751     * > means that the UA must, while the current node is not a tbody, tfoot, thead, template, or
     752     * > html element, pop elements from the stack of open elements.
     753     *
     754     * @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-stack-back-to-a-table-body-context
     755     *
     756     * @since 6.7.0
     757     */
     758    public function clear_to_table_body_context(): void {
     759        foreach ( $this->walk_up() as $item ) {
     760            if (
     761                'TBODY' === $item->node_name ||
     762                'TFOOT' === $item->node_name ||
     763                'THEAD' === $item->node_name ||
     764                'TEMPLATE' === $item->node_name ||
     765                'HTML' === $item->node_name
     766            ) {
     767                break;
     768            }
     769            $this->pop();
     770        }
     771    }
     772
     773    /**
     774     * Clear the stack back to a table row context.
     775     *
     776     * > When the steps above require the UA to clear the stack back to a table row context, it
     777     * > means that the UA must, while the current node is not a tr, template, or html element, pop
     778     * > elements from the stack of open elements.
     779     *
     780     * @see https://html.spec.whatwg.org/multipage/parsing.html#clear-the-stack-back-to-a-table-row-context
     781     *
     782     * @since 6.7.0
     783     */
     784    public function clear_to_table_row_context(): void {
     785        foreach ( $this->walk_up() as $item ) {
     786            if (
     787                'TR' === $item->node_name ||
     788                'TEMPLATE' === $item->node_name ||
     789                'HTML' === $item->node_name
     790            ) {
     791                break;
     792            }
     793            $this->pop();
     794        }
     795    }
     796
     797    /**
    724798     * Wakeup magic method.
    725799     *
Note: See TracChangeset for help on using the changeset viewer.