From 9a29748addcb2d953fd20fe82f22cd18672f4332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 28 Feb 2023 15:01:13 +0100 Subject: [PATCH] Cleanup the API --- .../html-api/class-wp-html-text-processor.php | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-text-processor.php b/src/wp-includes/html-api/class-wp-html-text-processor.php index 498e63eb2ad6a..f352b6d99da43 100644 --- a/src/wp-includes/html-api/class-wp-html-text-processor.php +++ b/src/wp-includes/html-api/class-wp-html-text-processor.php @@ -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() { @@ -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( @@ -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 ]; } } @@ -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; } @@ -1157,6 +1136,9 @@ private static function is_formatting_element( $tag_name ) { // die(); +$p = new WP_HTML_Processor( '
' ); +$p->parse(); +die(); $p = new WP_HTML_Processor( '

12345

' ); $p->parse();