Make WordPress Core


Ignore:
Timestamp:
06/25/2024 03:09:43 AM (2 years ago)
Author:
dmsnell
Message:

HTML API: Add missing subclass methods to HTML Processor and add token provenance.

This patch introduces two related changes:

  • It adds missing subclass methods on the HTML Processor which needed to be implemented since it started visiting virtual nodes. These methods need to account for the fact that not all tokens truly exist.
  • It adds a new concept and internal method, is_virtual(), indicating if the currently-matched token comes from the raw text in the input HTML document or if it was the byproduct of semantic parsing rules. This internal method and new vocabulary around token provenance considerably simplifies the logic spread throughout the rest of the class and its subclass methods.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/6860
Discussed in https://core.trac.wordpress.org/ticket/61348

Follow-up to [58304].

Props dmsnell, jonsurrell, gziolo.
See #61348.

File:
1 edited

Legend:

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

    r58304 r58558  
    5858
    5959        /**
     60         * Indicates if the stack element is a real or virtual node.
     61         *
     62         * @since 6.6.0
     63         *
     64         * @var string
     65         */
     66        public $provenance;
     67
     68        /**
    6069         * Constructor function.
    6170         *
    62          * @param WP_HTML_Token $token     Token associated with stack event, always an opening token.
    63          * @param string        $operation One of self::PUSH or self::POP.
     71         * @since 6.6.0
     72         *
     73         * @param WP_HTML_Token $token      Token associated with stack event, always an opening token.
     74         * @param string        $operation  One of self::PUSH or self::POP.
     75         * @param string        $provenance "virtual" or "real".
    6476         */
    65         public function __construct( $token, $operation ) {
    66                 $this->token     = $token;
    67                 $this->operation = $operation;
     77        public function __construct( $token, $operation, $provenance ) {
     78                $this->token      = $token;
     79                $this->operation  = $operation;
     80                $this->provenance = $provenance;
    6881        }
    6982}
Note: See TracChangeset for help on using the changeset viewer.