Skip to content

Commit

Permalink
Cleanup the API
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Feb 28, 2023
1 parent 481fce5 commit 9a29748
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions src/wp-includes/html-api/class-wp-html-text-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,17 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
* @var WP_HTML_Tag_Token[]
*/
private $active_formatting_elements = array();
private $root_node = null;
private $context_node = null;

private $element_bookmark_idx = 0;

/*
* WP_HTML_Tag_Processor skips over text nodes and only
* processes tags.
*
* WP_HTML_Processor needs to process text nodes as well.
*
* Whenever the tag processor skips over text to move to
* the next tag, the next_token() method emits that text
* as a token and stores the tag in $buffered_tag to be
* returned the next time.
*/
private $buffered_tag = null;

private $last_token = null;
private $inserted_tokens = array();

const MAX_BOOKMARKS = 1000000;

public function __construct( $html ) {
parent::__construct( $html );
$this->MARKER = new WP_HTML_Tag_Token(null);
$this->root_node = new WP_HTML_Tag_Token( 'HTML' );
$this->context_node = new WP_HTML_Tag_Token( 'DOCUMENT' );
$this->open_elements = array( $this->root_node );
$this->open_elements = array(
new WP_HTML_Tag_Token( 'HTML' )
);
}

public function parse() {
Expand Down Expand Up @@ -192,9 +174,9 @@ public function next_element_node() {
break;
case 'DD':
case 'DT':
$i = count( $this->open_elements ) - 1;
while ( true ) {
$node = $this->open_elements[ $i ];
$i = count( $this->open_elements );
while ( $i > 0 ) {
$node = $this->open_elements[ --$i ];
if ( $node->tag === 'DD' ) {
$this->generate_implied_end_tags(
array(
Expand All @@ -213,9 +195,6 @@ public function next_element_node() {
break;
} elseif ( self::is_special_element( $node->tag, array( 'ADDRESS', 'DIV', 'P' ) ) ) {
break;
} else {
--$i;
$node = $this->open_elements[ $i ];
}
}

Expand Down Expand Up @@ -776,7 +755,7 @@ private function close_p_element($insert_p_tag_closer = true) {
}

private function should_generate_implied_end_tags( $options = null ) {
$current_tag_name = $this->get_tag();
$current_tag_name = $this->current_node()->tag;
if ( null !== $options && isset( $options['except_for'] ) && in_array( $current_tag_name, $options['except_for'] ) ) {
return false;
}
Expand Down Expand Up @@ -1157,6 +1136,9 @@ private static function is_formatting_element( $tag_name ) {

// die();

$p = new WP_HTML_Processor( '<dd><dt>' );
$p->parse();
die();
$p = new WP_HTML_Processor( '<p>1<b>2<i>3</b>4</i>5</p>' );
$p->parse();

Expand Down

0 comments on commit 9a29748

Please sign in to comment.