Make WordPress Core


Ignore:
Timestamp:
08/23/2024 02:53:59 PM (18 months ago)
Author:
dmsnell
Message:

HTML API: Parse DOCTYPE tokens and set HTML parser mode accordingly.

This patch adds until-now missing code to parse the structure of HTML DOCTYPE declarations. The DOCTYPE is mostly unused but can dictate the document compatability mode, which governs whether CSS class names match in a ASCII-case-insensitive way or not, and whether TABLE elements close an open P element.

The DOCTYPE information is made available through a new method on the Tag Processor, get_doctype_info().

Developed in https://github.com/wordpress/wordpress-develop/pull/7195
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-processor.php

    r58898 r58925  
    10771077             */
    10781078            case 'html':
    1079                 $contents = $this->get_modifiable_text();
    1080                 if ( ' html' !== $contents ) {
    1081                     /*
    1082                      * @todo When the HTML Tag Processor fully parses the DOCTYPE declaration,
    1083                      *       this code should examine the contents to set the compatability mode.
    1084                      */
    1085                     $this->bail( 'Cannot process any DOCTYPE other than a normative HTML5 doctype.' );
     1079                $doctype = $this->get_doctype_info();
     1080                if ( null !== $doctype && 'quirks' === $doctype->indicated_compatability_mode ) {
     1081                    $this->state->document_mode = WP_HTML_Processor_State::QUIRKS_MODE;
    10861082                }
    10871083
     
    10901086                 */
    10911087                $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_BEFORE_HTML;
     1088                $this->insert_html_element( $this->state->current_token );
    10921089                return true;
    10931090        }
     
    10971094         */
    10981095        initial_anything_else:
     1096        $this->state->document_mode  = WP_HTML_Processor_State::QUIRKS_MODE;
    10991097        $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_BEFORE_HTML;
    11001098        return $this->step( self::REPROCESS_CURRENT_NODE );
Note: See TracChangeset for help on using the changeset viewer.