HTML API: Report real and virtual nodes in the HTML Processor.
HTML is a kind of short-hand for a DOM structure. This means that there are
many cases in HTML where an element's opening tag or closing tag is missing (or
both). This is because many of the parsing rules imply creating elements in the
DOM which may not exist in the text of the HTML.
The HTML Processor, being the higher-level counterpart to the Tag Processor, is
already aware of these nodes, but since it's inception has not paused on them
when scanning through a document. Instead, these are visible when pausing on a
child of such an element, but otherwise not seen.
In this patch the HTML Processor starts exposing those implicitly-created nodes,
including opening tags, and closing tags, that aren't foudn in the text content
of the HTML input document.
Previously, the sequence of matched tokens when scanning with
`WP_HTML_Processor::next_token()` would depend on how the HTML document was written,
but with this patch, all semantically equal HTML documents will parse and scan in
the same exact manner, presenting an idealized or "perfect" view of the document
the same way as would occur when traversing a DOM in a browser.
Developed in https://github.com/WordPress/wordpress-develop/pull/6348
Discussed in https://core.trac.wordpress.org/ticket/61348
Props audrasjb, dmsnell, gziolo, jonsurrell.
Fixes #61348.
Built from https://develop.svn.wordpress.org/trunk@58304
git-svn-id: http://core.svn.wordpress.org/trunk@57761 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-06-03 15:47:15 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* HTML API: WP_HTML_Stack_Event class
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage HTML-API
|
|
|
|
* @since 6.6.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Core class used by the HTML Processor as a record for stack operations.
|
|
|
|
*
|
|
|
|
* This class is for internal usage of the WP_HTML_Processor class.
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @since 6.6.0
|
|
|
|
*
|
|
|
|
* @see WP_HTML_Processor
|
|
|
|
*/
|
|
|
|
class WP_HTML_Stack_Event {
|
|
|
|
/**
|
|
|
|
* Refers to popping an element off of the stack of open elements.
|
|
|
|
*
|
|
|
|
* @since 6.6.0
|
|
|
|
*/
|
|
|
|
const POP = 'pop';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refers to pushing an element onto the stack of open elements.
|
|
|
|
*
|
|
|
|
* @since 6.6.0
|
|
|
|
*/
|
|
|
|
const PUSH = 'push';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* References the token associated with the stack push event,
|
|
|
|
* even if this is a pop event for that element.
|
|
|
|
*
|
|
|
|
* @since 6.6.0
|
|
|
|
*
|
|
|
|
* @var WP_HTML_Token
|
|
|
|
*/
|
|
|
|
public $token;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates which kind of stack operation this event represents.
|
|
|
|
*
|
|
|
|
* May be one of the class constants.
|
|
|
|
*
|
|
|
|
* @since 6.6.0
|
|
|
|
*
|
|
|
|
* @see self::POP
|
|
|
|
* @see self::PUSH
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $operation;
|
|
|
|
|
2024-06-24 23:11:19 -04:00
|
|
|
/**
|
|
|
|
* Indicates if the stack element is a real or virtual node.
|
|
|
|
*
|
|
|
|
* @since 6.6.0
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $provenance;
|
|
|
|
|
HTML API: Report real and virtual nodes in the HTML Processor.
HTML is a kind of short-hand for a DOM structure. This means that there are
many cases in HTML where an element's opening tag or closing tag is missing (or
both). This is because many of the parsing rules imply creating elements in the
DOM which may not exist in the text of the HTML.
The HTML Processor, being the higher-level counterpart to the Tag Processor, is
already aware of these nodes, but since it's inception has not paused on them
when scanning through a document. Instead, these are visible when pausing on a
child of such an element, but otherwise not seen.
In this patch the HTML Processor starts exposing those implicitly-created nodes,
including opening tags, and closing tags, that aren't foudn in the text content
of the HTML input document.
Previously, the sequence of matched tokens when scanning with
`WP_HTML_Processor::next_token()` would depend on how the HTML document was written,
but with this patch, all semantically equal HTML documents will parse and scan in
the same exact manner, presenting an idealized or "perfect" view of the document
the same way as would occur when traversing a DOM in a browser.
Developed in https://github.com/WordPress/wordpress-develop/pull/6348
Discussed in https://core.trac.wordpress.org/ticket/61348
Props audrasjb, dmsnell, gziolo, jonsurrell.
Fixes #61348.
Built from https://develop.svn.wordpress.org/trunk@58304
git-svn-id: http://core.svn.wordpress.org/trunk@57761 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-06-03 15:47:15 -04:00
|
|
|
/**
|
|
|
|
* Constructor function.
|
|
|
|
*
|
2024-06-24 23:11:19 -04:00
|
|
|
* @since 6.6.0
|
|
|
|
*
|
|
|
|
* @param WP_HTML_Token $token Token associated with stack event, always an opening token.
|
|
|
|
* @param string $operation One of self::PUSH or self::POP.
|
|
|
|
* @param string $provenance "virtual" or "real".
|
HTML API: Report real and virtual nodes in the HTML Processor.
HTML is a kind of short-hand for a DOM structure. This means that there are
many cases in HTML where an element's opening tag or closing tag is missing (or
both). This is because many of the parsing rules imply creating elements in the
DOM which may not exist in the text of the HTML.
The HTML Processor, being the higher-level counterpart to the Tag Processor, is
already aware of these nodes, but since it's inception has not paused on them
when scanning through a document. Instead, these are visible when pausing on a
child of such an element, but otherwise not seen.
In this patch the HTML Processor starts exposing those implicitly-created nodes,
including opening tags, and closing tags, that aren't foudn in the text content
of the HTML input document.
Previously, the sequence of matched tokens when scanning with
`WP_HTML_Processor::next_token()` would depend on how the HTML document was written,
but with this patch, all semantically equal HTML documents will parse and scan in
the same exact manner, presenting an idealized or "perfect" view of the document
the same way as would occur when traversing a DOM in a browser.
Developed in https://github.com/WordPress/wordpress-develop/pull/6348
Discussed in https://core.trac.wordpress.org/ticket/61348
Props audrasjb, dmsnell, gziolo, jonsurrell.
Fixes #61348.
Built from https://develop.svn.wordpress.org/trunk@58304
git-svn-id: http://core.svn.wordpress.org/trunk@57761 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-06-03 15:47:15 -04:00
|
|
|
*/
|
2024-07-19 19:44:16 -04:00
|
|
|
public function __construct( WP_HTML_Token $token, string $operation, string $provenance ) {
|
2024-06-24 23:11:19 -04:00
|
|
|
$this->token = $token;
|
|
|
|
$this->operation = $operation;
|
|
|
|
$this->provenance = $provenance;
|
HTML API: Report real and virtual nodes in the HTML Processor.
HTML is a kind of short-hand for a DOM structure. This means that there are
many cases in HTML where an element's opening tag or closing tag is missing (or
both). This is because many of the parsing rules imply creating elements in the
DOM which may not exist in the text of the HTML.
The HTML Processor, being the higher-level counterpart to the Tag Processor, is
already aware of these nodes, but since it's inception has not paused on them
when scanning through a document. Instead, these are visible when pausing on a
child of such an element, but otherwise not seen.
In this patch the HTML Processor starts exposing those implicitly-created nodes,
including opening tags, and closing tags, that aren't foudn in the text content
of the HTML input document.
Previously, the sequence of matched tokens when scanning with
`WP_HTML_Processor::next_token()` would depend on how the HTML document was written,
but with this patch, all semantically equal HTML documents will parse and scan in
the same exact manner, presenting an idealized or "perfect" view of the document
the same way as would occur when traversing a DOM in a browser.
Developed in https://github.com/WordPress/wordpress-develop/pull/6348
Discussed in https://core.trac.wordpress.org/ticket/61348
Props audrasjb, dmsnell, gziolo, jonsurrell.
Fixes #61348.
Built from https://develop.svn.wordpress.org/trunk@58304
git-svn-id: http://core.svn.wordpress.org/trunk@57761 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-06-03 15:47:15 -04:00
|
|
|
}
|
|
|
|
}
|