Make WordPress Core


Ignore:
Timestamp:
07/22/2024 10:22:03 PM (2 years ago)
Author:
dmsnell
Message:

HTML API: Add missing tags in IN BODY insertion mode to HTML Processor.

As part of work to add more spec support to the HTML API, this patch adds
support for the remaining missing tags in the IN BODY insertion mode. Not
all of the added tags are supported, because in some cases they reset the
insertion mode and are reprocessed where they will be rejected.

This patch also improves the support of get_modifiable_text(), removing
a leading newline inside a LISTING, PRE, or TEXTAREA element.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/6972
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

    r58742 r58779  
    3232         */
    3333        const SKIP_TESTS = array(
    34                 'adoption01/line0046'       => 'Unimplemented: Reconstruction of active formatting elements.',
    35                 'adoption01/line0159'       => 'Unimplemented: Reconstruction of active formatting elements.',
    36                 'adoption01/line0318'       => 'Unimplemented: Reconstruction of active formatting elements.',
    37                 'inbody01/line0001'         => 'Bug.',
    38                 'inbody01/line0014'         => 'Bug.',
    39                 'inbody01/line0029'         => 'Bug.',
    40                 'menuitem-element/line0012' => 'Bug.',
    41                 'tests1/line0342'           => "Closing P tag implicitly creates opener, which we don't visit.",
    42                 'tests1/line0720'           => 'Unimplemented: Reconstruction of active formatting elements.',
    43                 'tests15/line0001'          => 'Unimplemented: Reconstruction of active formatting elements.',
    44                 'tests15/line0022'          => 'Unimplemented: Reconstruction of active formatting elements.',
    45                 'tests2/line0650'           => 'Whitespace only test never enters "in body" parsing mode.',
    46                 'tests20/line0497'          => "Closing P tag implicitly creates opener, which we don't visit.",
    47                 'tests23/line0001'          => 'Unimplemented: Reconstruction of active formatting elements.',
    48                 'tests23/line0041'          => 'Unimplemented: Reconstruction of active formatting elements.',
    49                 'tests23/line0069'          => 'Unimplemented: Reconstruction of active formatting elements.',
    50                 'tests23/line0101'          => 'Unimplemented: Reconstruction of active formatting elements.',
    51                 'tests25/line0169'          => 'Bug.',
    52                 'tests26/line0263'          => 'Bug: An active formatting element should be created for a trailing text node.',
     34                'adoption01/line0046' => 'Unimplemented: Reconstruction of active formatting elements.',
     35                'adoption01/line0159' => 'Unimplemented: Reconstruction of active formatting elements.',
     36                'adoption01/line0318' => 'Unimplemented: Reconstruction of active formatting elements.',
     37                'tests1/line0720'     => 'Unimplemented: Reconstruction of active formatting elements.',
     38                'tests15/line0001'    => 'Unimplemented: Reconstruction of active formatting elements.',
     39                'tests15/line0022'    => 'Unimplemented: Reconstruction of active formatting elements.',
     40                'tests15/line0068'    => 'Unimplemented: no support outside of IN BODY yet.',
     41                'tests2/line0650'     => 'Whitespace only test never enters "in body" parsing mode.',
     42                'tests19/line0965'    => 'Unimplemented: no support outside of IN BODY yet.',
     43                'tests23/line0001'    => 'Unimplemented: Reconstruction of active formatting elements.',
     44                'tests23/line0041'    => 'Unimplemented: Reconstruction of active formatting elements.',
     45                'tests23/line0069'    => 'Unimplemented: Reconstruction of active formatting elements.',
     46                'tests23/line0101'    => 'Unimplemented: Reconstruction of active formatting elements.',
     47                'tests26/line0263'    => 'Bug: An active formatting element should be created for a trailing text node.',
     48                'webkit01/line0231'   => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
     49                'webkit02/line0013'   => "Asserting behavior with scripting flag enabled, which this parser doesn't support.",
     50                'webkit01/line0300'   => 'Unimplemented: no support outside of IN BODY yet.',
     51                'webkit01/line0310'   => 'Unimplemented: no support outside of IN BODY yet.',
     52                'webkit01/line0336'   => 'Unimplemented: no support outside of IN BODY yet.',
     53                'webkit01/line0349'   => 'Unimplemented: no support outside of IN BODY yet.',
     54                'webkit01/line0362'   => 'Unimplemented: no support outside of IN BODY yet.',
     55                'webkit01/line0375'   => 'Unimplemented: no support outside of IN BODY yet.',
    5356        );
    5457
    … …  
    199202                                                        $output .= str_repeat( $indent, $tag_indent + 1 ) . "{$attribute_name}=\"{$val}\"\n";
    200203                                                }
    201 
    202                                                 // Self-contained tags contain their inner contents as modifiable text.
    203                                                 $modifiable_text = $processor->get_modifiable_text();
    204                                                 if ( '' !== $modifiable_text ) {
    205                                                         $was_text = true;
    206                                                         if ( '' === $text_node ) {
    207                                                                 $text_node = str_repeat( $indent, $indent_level ) . '"';
    208                                                         }
    209                                                         $text_node .= $modifiable_text;
    210                                                         --$indent_level;
    211                                                 }
     204                                        }
     205
     206                                        // Self-contained tags contain their inner contents as modifiable text.
     207                                        $modifiable_text = $processor->get_modifiable_text();
     208                                        if ( '' !== $modifiable_text ) {
     209                                                $output .= str_repeat( $indent, $indent_level ) . "\"{$modifiable_text}\"\n";
     210                                        }
     211
     212                                        if ( ! $processor->is_void( $tag_name ) && ! $processor->expects_closer() ) {
     213                                                --$indent_level;
    212214                                        }
    213215
    … …  
    226228                                                case WP_HTML_Processor::COMMENT_AS_ABRUPTLY_CLOSED_COMMENT:
    227229                                                case WP_HTML_Processor::COMMENT_AS_HTML_COMMENT:
     230                                                case WP_HTML_Processor::COMMENT_AS_INVALID_HTML:
    228231                                                        $comment_text_content = $processor->get_modifiable_text();
    229232                                                        break;
Note: See TracChangeset for help on using the changeset viewer.