Make WordPress Core

Changeset 57314


Ignore:
Timestamp:
01/19/2024 07:01:29 PM (5 weeks ago)
Author:
dmsnell
Message:

HTML API: Add support for HR element.

Adds support for the following HTML elements to the HTML Processor:

  • HR

Previously, this element was not supported and the HTML Processor would bail when encountering
it. Now, with this patch, it will proceed to parse an HTML document when encountering one.

Developed in WordPress/wordpress-develop#5897

Props jonsurrell, dmsnell
Fixes #60283

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r57264 r57314  
    110110 *  - Paragraph: P.
    111111 *  - Phrasing elements: ABBR, BDI, BDO, CITE, DATA, DEL, DFN, INS, MARK, OUTPUT, Q, SAMP, SUB, SUP, TIME, VAR.
    112  *  - Sectioning elements: ARTICLE, ASIDE, NAV, SECTION.
     112 *  - Sectioning elements: ARTICLE, ASIDE, HR, NAV, SECTION.
    113113 *  - Templating elements: SLOT.
    114114 *  - Text decoration: RUBY.
     
    941941                $this->reconstruct_active_formatting_elements();
    942942                $this->insert_html_element( $this->state->current_token );
     943                return true;
     944
     945            /*
     946             * > A start tag whose tag name is "hr"
     947             */
     948            case '+HR':
     949                if ( $this->state->stack_of_open_elements->has_p_in_button_scope() ) {
     950                    $this->close_a_p_element();
     951                }
     952                $this->insert_html_element( $this->state->current_token );
     953                $this->state->frameset_ok = false;
    943954                return true;
    944955        }
     
    978989            case 'FRAMESET':
    979990            case 'HEAD':
    980             case 'HR':
    981991            case 'HTML':
    982992            case 'IFRAME':
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php

    r57264 r57314  
    174174            'FRAMESET'  => array( 'FRAMESET' ),
    175175            'HEAD'      => array( 'HEAD' ),
    176             'HR'        => array( 'HR' ),
    177176            'HTML'      => array( 'HTML' ),
    178177            'IFRAME'    => array( 'IFRAME' ),
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php

    r57264 r57314  
    176176            'FRAMESET',
    177177            'HEAD',
    178             'HR',
    179178            'HTML',
    180179            'IFRAME',
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php

    r57264 r57314  
    226226
    227227    /**
     228     * Verifies that HR closes an open p tag
     229     *
     230     * @ticket 60283
     231     */
     232    public function test_in_body_hr_element_closes_open_p_tag() {
     233        $processor = WP_HTML_Processor::create_fragment( '<p><hr>' );
     234
     235        $processor->next_tag( 'HR' );
     236        $this->assertSame(
     237            array( 'HTML', 'BODY', 'HR' ),
     238            $processor->get_breadcrumbs(),
     239            'Expected HR to be a direct child of the BODY, having closed the open P element.'
     240        );
     241    }
     242
     243    /**
    228244     * Verifies that H1 through H6 elements close an open P element.
    229245     *
Note: See TracChangeset for help on using the changeset viewer.