Skip to content

Commit

Permalink
HTML API: Add support for HR element.
Browse files Browse the repository at this point in the history
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#5897

Props jonsurrell, dmsnell
Fixes #60283



git-svn-id: https://develop.svn.wordpress.org/trunk@57314 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
dmsnell committed Jan 19, 2024
1 parent 27ac620 commit ecbd137
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
* - Media elements: AUDIO, CANVAS, FIGCAPTION, FIGURE, IMG, MAP, PICTURE, VIDEO.
* - Paragraph: P.
* - Phrasing elements: ABBR, BDI, BDO, CITE, DATA, DEL, DFN, INS, MARK, OUTPUT, Q, SAMP, SUB, SUP, TIME, VAR.
* - Sectioning elements: ARTICLE, ASIDE, NAV, SECTION.
* - Sectioning elements: ARTICLE, ASIDE, HR, NAV, SECTION.
* - Templating elements: SLOT.
* - Text decoration: RUBY.
* - Deprecated elements: ACRONYM, BLINK, CENTER, DIR, ISINDEX, MULTICOL, NEXTID, SPACER.
Expand Down Expand Up @@ -941,6 +941,17 @@ private function step_in_body() {
$this->reconstruct_active_formatting_elements();
$this->insert_html_element( $this->state->current_token );
return true;

/*
* > A start tag whose tag name is "hr"
*/
case '+HR':
if ( $this->state->stack_of_open_elements->has_p_in_button_scope() ) {
$this->close_a_p_element();
}
$this->insert_html_element( $this->state->current_token );
$this->state->frameset_ok = false;
return true;
}

/*
Expand Down Expand Up @@ -977,7 +988,6 @@ private function step_in_body() {
case 'FRAME':
case 'FRAMESET':
case 'HEAD':
case 'HR':
case 'HTML':
case 'IFRAME':
case 'INPUT':
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/tests/html-api/wpHtmlProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public function data_unsupported_special_in_body_tags() {
'FRAME' => array( 'FRAME' ),
'FRAMESET' => array( 'FRAMESET' ),
'HEAD' => array( 'HEAD' ),
'HR' => array( 'HR' ),
'HTML' => array( 'HTML' ),
'IFRAME' => array( 'IFRAME' ),
'INPUT' => array( 'INPUT' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public function data_unsupported_elements() {
'FRAME',
'FRAMESET',
'HEAD',
'HR',
'HTML',
'IFRAME',
'INPUT',
Expand Down
16 changes: 16 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ public function test_in_body_button_with_button_in_scope_as_ancestor() {
$this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' );
}

/**
* Verifies that HR closes an open p tag
*
* @ticket 60283
*/
public function test_in_body_hr_element_closes_open_p_tag() {
$processor = WP_HTML_Processor::create_fragment( '<p><hr>' );

$processor->next_tag( 'HR' );
$this->assertSame(
array( 'HTML', 'BODY', 'HR' ),
$processor->get_breadcrumbs(),
'Expected HR to be a direct child of the BODY, having closed the open P element.'
);
}

/**
* Verifies that H1 through H6 elements close an open P element.
*
Expand Down

0 comments on commit ecbd137

Please sign in to comment.