Make WordPress Core


Ignore:
Timestamp:
08/08/2024 07:23:53 AM (11 months ago)
Author:
dmsnell
Message:

HTML API: Add support for SVG and MathML (Foreign content)

As part of work to add more spec support to the HTML API, this patch adds
support for SVG and MathML elements, or more generally, "foreign content."

The rules in foreign content are a mix of XML and HTML parsing rules and
introduce additional complexity into the processor, but is important in
order to avoid getting lost when inside these elements.

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

    r58836 r58867  
    166166
    167167    /**
    168      * Ensures that no new HTML elements are accidentally partially-supported.
    169      *
    170      * When introducing support for new HTML elements, there are multiple places
    171      * in the HTML Processor that need to be updated, until the time that the class
    172      * has full HTML5 support. Because of this, these tests lock down the interface
    173      * to ensure that support isn't accidentally updated in one place for a new
    174      * element while overlooked in another.
    175      *
    176      * @ticket 58517
    177      *
    178      * @covers WP_HTML_Processor::step
    179      *
    180      * @dataProvider data_unsupported_elements
    181      *
    182      * @param string $html HTML string containing unsupported elements.
    183      */
    184     public function test_fails_when_encountering_unsupported_tag( $html ) {
    185         $processor = WP_HTML_Processor::create_fragment( $html );
    186 
    187         $this->assertFalse( $processor->step(), "Should not have stepped into unsupported {$processor->get_tag()} element." );
    188     }
    189 
    190     /**
    191      * Data provider.
    192      *
    193      * @return array[]
    194      */
    195     public static function data_unsupported_elements() {
    196         $unsupported_elements = array(
    197             'MATH',
    198             'PLAINTEXT', // Neutralized.
    199             'SVG',
    200         );
    201 
    202         $data = array();
    203         foreach ( $unsupported_elements as $tag_name ) {
    204             $data[ $tag_name ] = array( "<{$tag_name}>" );
    205         }
    206 
    207         return $data;
    208     }
    209 
    210     /**
    211168     * @ticket 58517
    212169     *
Note: See TracChangeset for help on using the changeset viewer.