Make WordPress Core


Ignore:
Timestamp:
08/23/2024 02:53:59 PM (2 years 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/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php

    r58893 r58925  
    29402940                $this->assertTrue( $processor->paused_at_incomplete_token() );
    29412941        }
     2942
     2943        /**
     2944         * Test basic DOCTYPE handling.
     2945         *
     2946         * @ticket 61576
     2947         */
     2948        public function test_doctype_doc_name() {
     2949                $processor = new WP_HTML_Tag_Processor( '<!DOCTYPE html>' );
     2950                $this->assertTrue( $processor->next_token() );
     2951                $doctype = $processor->get_doctype_info();
     2952                $this->assertNotNull( $doctype );
     2953                $this->assertSame( 'html', $doctype->name );
     2954                $this->assertSame( 'no-quirks', $doctype->indicated_compatability_mode );
     2955                $this->assertNull( $doctype->public_identifier );
     2956                $this->assertNull( $doctype->system_identifier );
     2957        }
    29422958}
Note: See TracChangeset for help on using the changeset viewer.