Make WordPress Core


Ignore:
Timestamp:
02/04/2025 02:47:41 AM (19 months ago)
Author:
jorbin
Message:

HTML API: Fix extensibility of WP_HTML_Processor::next_token().

Break out logic from the next_token() method into a private method which may call itself recursively. This allows for subclasses to override the next_token() method and be assured that each call to next_token() corresponds with the consumption of one single token. This also parallels how WP_HTML_Tag_Processor::next_token() wraps a private base_class_next_token() method.

Reviewed by jonsurrell.
Merges [59285], [59364], and [59747] to 6.7 branch.

Props westonruter, jonsurrell, dmsnell, jorbin.

File:
1 edited

Legend:

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

    r59721 r59757  
    609609
    610610        /**
    611          * Ensures internal accounting is maintained for HTML semantic rules while
    612          * the underlying Tag Processor class is seeking to a bookmark.
     611         * Finds the next token in the HTML document.
    613612         *
    614613         * This doesn't currently have a way to represent non-tags and doesn't process
     
    617616         *
    618617         * @since 6.5.0 Added for internal support; do not use.
     618         * @since 6.7.2 Refactored so subclasses may extend.
     619         *
     620         * @return bool Whether a token was parsed.
     621         */
     622        public function next_token(): bool {
     623                return $this->next_visitable_token();
     624        }
     625
     626        /**
     627         * Ensures internal accounting is maintained for HTML semantic rules while
     628         * the underlying Tag Processor class is seeking to a bookmark.
     629         *
     630         * This doesn't currently have a way to represent non-tags and doesn't process
     631         * semantic rules for text nodes. For access to the raw tokens consider using
     632         * WP_HTML_Tag_Processor instead.
     633         *
     634         * Note that this method may call itself recursively. This is why it is not
     635         * implemented as {@see WP_HTML_Processor::next_token()}, which instead calls
     636         * this method similarly to how {@see WP_HTML_Tag_Processor::next_token()}
     637         * calls the {@see WP_HTML_Tag_Processor::base_class_next_token()} method.
     638         *
     639         * @since 6.7.2 Added for internal support.
    619640         *
    620641         * @access private
     
    622643         * @return bool
    623644         */
    624         public function next_token(): bool {
     645        private function next_visitable_token(): bool {
    625646                $this->current_element = null;
    626647
     
    640661                 */
    641662                if ( empty( $this->element_queue ) && $this->step() ) {
    642                         return $this->next_token();
     663                        return $this->next_visitable_token();
    643664                }
    644665
     
    651672                        }
    652673
    653                         return empty( $this->element_queue ) ? false : $this->next_token();
     674                        return empty( $this->element_queue ) ? false : $this->next_visitable_token();
    654675                }
    655676
     
    662683                 */
    663684                if ( 'root-node' === $this->current_element->token->bookmark_name ) {
    664                         return $this->next_token();
     685                        return $this->next_visitable_token();
    665686                }
    666687
     
    674695                // Avoid sending close events for elements which don't expect a closing.
    675696                if ( $is_pop && ! $this->expects_closer( $this->current_element->token ) ) {
    676                         return $this->next_token();
     697                        return $this->next_visitable_token();
    677698                }
    678699
Note: See TracChangeset for help on using the changeset viewer.