Make WordPress Core


Ignore:
Timestamp:
07/30/2024 06:44:45 PM (19 months ago)
Author:
dmsnell
Message:

HTML API: Add TEMPLATE and related support in HTML Processor.

As part of work to add more spec support to the HTML API, this patch adds
support for the IN TEMPLATE and IN HEAD insertion modes. These changes are
primarily about adding support for TEMPLATE elements in the HTML Processor,
but include support for other tags commonly found in the document head, such
as LINK, META, SCRIPT, STYLE, and TITLE.

Developed in https://github.com/wordpress/wordpress-develop/pull/7046
Discussed in https://core.trac.wordpress.org/ticket/61576

Props: dmsnell, jonsurrell, westonruter.
See #61576.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

    r58779 r58833  
    3535        'adoption01/line0159' => 'Unimplemented: Reconstruction of active formatting elements.',
    3636        'adoption01/line0318' => 'Unimplemented: Reconstruction of active formatting elements.',
     37        'template/line0885'   => 'Unimplemented: no parsing of attributes on context node.',
    3738        'tests1/line0720'     => 'Unimplemented: Reconstruction of active formatting elements.',
    3839        'tests15/line0001'    => 'Unimplemented: Reconstruction of active formatting elements.',
     
    164165            }
    165166
    166             if ( $was_text && '#text' !== $processor->get_token_name() ) {
     167            $token_name = $processor->get_token_name();
     168            $token_type = $processor->get_token_type();
     169            $is_closer  = $processor->is_tag_closer();
     170
     171            if ( $was_text && '#text' !== $token_name ) {
    167172                $output   .= "{$text_node}\"\n";
    168173                $was_text  = false;
     
    170175            }
    171176
    172             switch ( $processor->get_token_type() ) {
     177            switch ( $token_type ) {
    173178                case '#tag':
    174                     $tag_name = strtolower( $processor->get_tag() );
    175 
    176                     if ( $processor->is_tag_closer() ) {
     179                    $tag_name = strtolower( $token_name );
     180
     181                    if ( $is_closer ) {
    177182                        --$indent_level;
     183
     184                        if ( 'TEMPLATE' === $token_name ) {
     185                            --$indent_level;
     186                        }
     187
    178188                        break;
    179189                    }
    180190
    181                     $tag_indent = count( $processor->get_breadcrumbs() ) - 1;
     191                    $tag_indent = $indent_level;
    182192
    183193                    if ( ! WP_HTML_Processor::is_void( $tag_name ) ) {
    184                         $indent_level = $tag_indent + 1;
     194                        ++$indent_level;
    185195                    }
    186196
     
    208218                    if ( '' !== $modifiable_text ) {
    209219                        $output .= str_repeat( $indent, $indent_level ) . "\"{$modifiable_text}\"\n";
     220                    }
     221
     222                    if ( 'TEMPLATE' === $token_name ) {
     223                        $output .= str_repeat( $indent, $indent_level ) . "content\n";
     224                        ++$indent_level;
    210225                    }
    211226
Note: See TracChangeset for help on using the changeset viewer.