??????????????
PK <»–[~¸# # " class-wp-html-text-replacement.phpnu „[µü¤ start = $start;
$this->end = $end;
$this->text = $text;
}
}
PK <»–[
Á
È
! class-wp-html-processor-state.phpnu „[µü¤ The frameset-ok flag is set to "ok" when the parser is created. It is set to "not ok" after certain tokens are seen.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#frameset-ok-flag
*
* @var bool
*/
public $frameset_ok = true;
/**
* Constructor - creates a new and empty state value.
*
* @since 6.4.0
*
* @see WP_HTML_Processor
*/
public function __construct() {
$this->stack_of_open_elements = new WP_HTML_Open_Elements();
$this->active_formatting_elements = new WP_HTML_Active_Formatting_Elements();
}
}
PK <»–[t5â¿ð
ð
class-wp-html-token.phpnu „[µü¤ bookmark_name = $bookmark_name;
$this->node_name = $node_name;
$this->has_self_closing_flag = $has_self_closing_flag;
$this->on_destroy = $on_destroy;
}
/**
* Destructor.
*
* @since 6.4.0
*/
public function __destruct() {
if ( is_callable( $this->on_destroy ) ) {
call_user_func( $this->on_destroy, $this->bookmark_name );
}
}
/**
* Wakeup magic method.
*
* @since 6.4.2
*/
public function __wakeup() {
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
}
}
PK <»–[å
Ôù
c
c class-wp-html-doctype-info.phpnu „[µü¤ `.
*
* > DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different
* > rendering mode that is incompatible with some specifications. Including the DOCTYPE in a
* > document ensures that the browser makes a best-effort attempt at following the
* > relevant specifications.
*
* @see https://html.spec.whatwg.org/#the-doctype
*
* DOCTYPE declarations comprise four properties: a name, public identifier, system identifier,
* and an indication of which document compatability mode they would imply if an HTML parser
* hadn't already determined it from other information.
*
* @see https://html.spec.whatwg.org/#the-initial-insertion-mode
*
* Historically, the DOCTYPE declaration was used in SGML documents to instruct a parser how
* to interpret the various tags and entities within a document. Its role in HTML diverged
* from how it was used in SGML and no meaning should be back-read into HTML based on how it
* is used in SGML, XML, or XHTML documents.
*
* @see https://www.iso.org/standard/16387.html
*
* @since 6.7.0
*
* @see WP_HTML_Processor
*/
class WP_HTML_Doctype_Info {
/**
* Name of the DOCTYPE: should be "html" for HTML documents.
*
* This value should be considered "read only" and not modified.
*
* Historically the DOCTYPE name indicates name of the document's root element.
*
*
* ╰──┴── name is "html".
*
* @see https://html.spec.whatwg.org/#tokenization
*
* @since 6.7.0
*
* @var string|null
*/
public $name = null;
/**
* Public identifier of the DOCTYPE.
*
* This value should be considered "read only" and not modified.
*
* The public identifier is optional and should not appear in HTML documents.
* A `null` value indicates that no public identifier was present in the DOCTYPE.
*
* Historically the presence of the public identifier indicated that a document
* was meant to be shared between computer systems and the value indicated to a
* knowledgeable parser how to find the relevant document type definition (DTD).
*
*
* │ │ ╰─── public identifier ─────╯
* ╰──┴── name is "html".
*
* @see https://html.spec.whatwg.org/#tokenization
*
* @since 6.7.0
*
* @var string|null
*/
public $public_identifier = null;
/**
* System identifier of the DOCTYPE.
*
* This value should be considered "read only" and not modified.
*
* The system identifier is optional and should not appear in HTML documents.
* A `null` value indicates that no system identifier was present in the DOCTYPE.
*
* Historically the system identifier specified where a relevant document type
* declaration for the given document is stored and may be retrieved.
*
*
* │ │ ╰──── system identifier ────╯
* ╰──┴── name is "html".
*
* If a public identifier were provided it would indicate to a knowledgeable
* parser how to interpret the system identifier.
*
*
* │ │ ╰─── public identifier ─────╯ ╰──── system identifier ────╯
* ╰──┴── name is "html".
*
* @see https://html.spec.whatwg.org/#tokenization
*
* @since 6.7.0
*
* @var string|null
*/
public $system_identifier = null;
/**
* Which document compatability mode this DOCTYPE declaration indicates.
*
* This value should be considered "read only" and not modified.
*
* When an HTML parser has not already set the document compatability mode,
* (e.g. "quirks" or "no-quirks" mode), it will infer if from the properties
* of the appropriate DOCTYPE declaration, if one exists. The DOCTYPE can
* indicate one of three possible document compatability modes:
*
* - "no-quirks" and "limited-quirks" modes (also called "standards" mode).
* - "quirks" mode (also called `CSS1Compat` mode).
*
* An appropriate DOCTYPE is one encountered in the "initial" insertion mode,
* before the HTML element has been opened and before finding any other
* DOCTYPE declaration tokens.
*
* @see https://html.spec.whatwg.org/#the-initial-insertion-mode
*
* @since 6.7.0
*
* @var string One of "no-quirks", "limited-quirks", or "quirks".
*/
public $indicated_compatability_mode;
/**
* Constructor.
*
* This class should not be instantiated directly.
* Use the static {@see self::from_doctype_token} method instead.
*
* The arguments to this constructor correspond to the "DOCTYPE token"
* as defined in the HTML specification.
*
* > DOCTYPE tokens have a name, a public identifier, a system identifier,
* > and a force-quirks flag. When a DOCTYPE token is created, its name, public identifier,
* > and system identifier must be marked as missing (which is a distinct state from the
* > empty string), and the force-quirks flag must be set to off (its other state is on).
*
* @see https://html.spec.whatwg.org/multipage/parsing.html#tokenization
*
* @since 6.7.0
*
* @param string|null $name Name of the DOCTYPE.
* @param string|null $public_identifier Public identifier of the DOCTYPE.
* @param string|null $system_identifier System identifier of the DOCTYPE.
* @param bool $force_quirks_flag Whether the force-quirks flag is set for the token.
*/
private function __construct(
?string $name,
?string $public_identifier,
?string $system_identifier,
bool $force_quirks_flag
) {
$this->name = $name;
$this->public_identifier = $public_identifier;
$this->system_identifier = $system_identifier;
/*
* > If the DOCTYPE token matches one of the conditions in the following list,
* > then set the Document to quirks mode:
*/
/*
* > The force-quirks flag is set to on.
*/
if ( $force_quirks_flag ) {
$this->indicated_compatability_mode = 'quirks';
return;
}
/*
* Normative documents will contain the literal `` with no
* public or system identifiers; short-circuit to avoid extra parsing.
*/
if ( 'html' === $name && null === $public_identifier && null === $system_identifier ) {
$this->indicated_compatability_mode = 'no-quirks';
return;
}
/*
* > The name is not "html".
*
* The tokenizer must report the name in lower case even if provided in
* the document in upper case; thus no conversion is required here.
*/
if ( 'html' !== $name ) {
$this->indicated_compatability_mode = 'quirks';
return;
}
/*
* Set up some variables to handle the rest of the conditions.
*
* > set...the public identifier...to...the empty string if the public identifier was missing.
* > set...the system identifier...to...the empty string if the system identifier was missing.
* >
* > The system identifier and public identifier strings must be compared...
* > in an ASCII case-insensitive manner.
* >
* > A system identifier whose value is the empty string is not considered missing
* > for the purposes of the conditions above.
*/
$system_identifier_is_missing = null === $system_identifier;
$public_identifier = null === $public_identifier ? '' : strtolower( $public_identifier );
$system_identifier = null === $system_identifier ? '' : strtolower( $system_identifier );
/*
* > The public identifier is set to…
*/
if (
'-//w3o//dtd w3 html strict 3.0//en//' === $public_identifier ||
'-/w3c/dtd html 4.0 transitional/en' === $public_identifier ||
'html' === $public_identifier
) {
$this->indicated_compatability_mode = 'quirks';
return;
}
/*
* > The system identifier is set to…
*/
if ( 'http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd' === $system_identifier ) {
$this->indicated_compatability_mode = 'quirks';
return;
}
/*
* All of the following conditions depend on matching the public identifier.
* If the public identifier is empty, none of the following conditions will match.
*/
if ( '' === $public_identifier ) {
$this->indicated_compatability_mode = 'no-quirks';
return;
}
/*
* > The public identifier starts with…
*
* @todo Optimize this matching. It shouldn't be a large overall performance issue,
* however, as only a single DOCTYPE declaration token should ever be parsed,
* and normative documents will have exited before reaching this condition.
*/
if (
str_starts_with( $public_identifier, '+//silmaril//dtd html pro v0r11 19970101//' ) ||
str_starts_with( $public_identifier, '-//as//dtd html 3.0 aswedit + extensions//' ) ||
str_starts_with( $public_identifier, '-//advasoft ltd//dtd html 3.0 aswedit + extensions//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 2.0 level 1//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 2.0 level 2//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 2.0 strict level 1//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 2.0 strict level 2//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 2.0 strict//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 2.0//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 2.1e//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 3.0//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 3.2 final//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 3.2//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html 3//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html level 0//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html level 1//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html level 2//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html level 3//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html strict level 0//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html strict level 1//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html strict level 2//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html strict level 3//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html strict//' ) ||
str_starts_with( $public_identifier, '-//ietf//dtd html//' ) ||
str_starts_with( $public_identifier, '-//metrius//dtd metrius presentational//' ) ||
str_starts_with( $public_identifier, '-//microsoft//dtd internet explorer 2.0 html strict//' ) ||
str_starts_with( $public_identifier, '-//microsoft//dtd internet explorer 2.0 html//' ) ||
str_starts_with( $public_identifier, '-//microsoft//dtd internet explorer 2.0 tables//' ) ||
str_starts_with( $public_identifier, '-//microsoft//dtd internet explorer 3.0 html strict//' ) ||
str_starts_with( $public_identifier, '-//microsoft//dtd internet explorer 3.0 html//' ) ||
str_starts_with( $public_identifier, '-//microsoft//dtd internet explorer 3.0 tables//' ) ||
str_starts_with( $public_identifier, '-//netscape comm. corp.//dtd html//' ) ||
str_starts_with( $public_identifier, '-//netscape comm. corp.//dtd strict html//' ) ||
str_starts_with( $public_identifier, "-//o'reilly and associates//dtd html 2.0//" ) ||
str_starts_with( $public_identifier, "-//o'reilly and associates//dtd html extended 1.0//" ) ||
str_starts_with( $public_identifier, "-//o'reilly and associates//dtd html extended relaxed 1.0//" ) ||
str_starts_with( $public_identifier, '-//sq//dtd html 2.0 hotmetal + extensions//' ) ||
str_starts_with( $public_identifier, '-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//' ) ||
str_starts_with( $public_identifier, '-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//' ) ||
str_starts_with( $public_identifier, '-//spyglass//dtd html 2.0 extended//' ) ||
str_starts_with( $public_identifier, '-//sun microsystems corp.//dtd hotjava html//' ) ||
str_starts_with( $public_identifier, '-//sun microsystems corp.//dtd hotjava strict html//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html 3 1995-03-24//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html 3.2 draft//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html 3.2 final//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html 3.2//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html 3.2s draft//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html 4.0 frameset//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html 4.0 transitional//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html experimental 19960712//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html experimental 970421//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd w3 html//' ) ||
str_starts_with( $public_identifier, '-//w3o//dtd w3 html 3.0//' ) ||
str_starts_with( $public_identifier, '-//webtechs//dtd mozilla html 2.0//' ) ||
str_starts_with( $public_identifier, '-//webtechs//dtd mozilla html//' )
) {
$this->indicated_compatability_mode = 'quirks';
return;
}
/*
* > The system identifier is missing and the public identifier starts with…
*/
if (
$system_identifier_is_missing && (
str_starts_with( $public_identifier, '-//w3c//dtd html 4.01 frameset//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html 4.01 transitional//' )
)
) {
$this->indicated_compatability_mode = 'quirks';
return;
}
/*
* > Otherwise, if the DOCTYPE token matches one of the conditions in
* > the following list, then set the Document to limited-quirks mode.
*/
/*
* > The public identifier starts with…
*/
if (
str_starts_with( $public_identifier, '-//w3c//dtd xhtml 1.0 frameset//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd xhtml 1.0 transitional//' )
) {
$this->indicated_compatability_mode = 'limited-quirks';
return;
}
/*
* > The system identifier is not missing and the public identifier starts with…
*/
if (
! $system_identifier_is_missing && (
str_starts_with( $public_identifier, '-//w3c//dtd html 4.01 frameset//' ) ||
str_starts_with( $public_identifier, '-//w3c//dtd html 4.01 transitional//' )
)
) {
$this->indicated_compatability_mode = 'limited-quirks';
return;
}
$this->indicated_compatability_mode = 'no-quirks';
}
/**
* Creates a WP_HTML_Doctype_Info instance by parsing a raw DOCTYPE declaration token.
*
* Use this method to parse a DOCTYPE declaration token and get access to its properties
* via the returned WP_HTML_Doctype_Info class instance. The provided input must parse
* properly as a DOCTYPE declaration, though it must not represent a valid DOCTYPE.
*
* Example:
*
* // Normative HTML DOCTYPE declaration.
* $doctype = WP_HTML_Doctype_Info::from_doctype_token( '' );
* 'no-quirks' === $doctype->indicated_compatability_mode;
*
* // A nonsensical DOCTYPE is still valid, and will indicate "quirks" mode.
* $doctype = WP_HTML_Doctype_Info::from_doctype_token( '' );
* 'quirks' === $doctype->indicated_compatability_mode;
*
* // Textual quirks present in raw HTML are handled appropriately.
* $doctype = WP_HTML_Doctype_Info::from_doctype_token( "" );
* 'no-quirks' === $doctype->indicated_compatability_mode;
*
* // Anything other than a proper DOCTYPE declaration token fails to parse.
* null === WP_HTML_Doctype_Info::from_doctype_token( ' ' );
* null === WP_HTML_Doctype_Info::from_doctype_token( '
' );
* null === WP_HTML_Doctype_Info::from_doctype_token( '' );
* null === WP_HTML_Doctype_Info::from_doctype_token( 'html' );
* null === WP_HTML_Doctype_Info::from_doctype_token( '' );
*
* @since 6.7.0
*
* @param string $doctype_html The complete raw DOCTYPE HTML string, e.g. ``.
*
* @return WP_HTML_Doctype_Info|null A WP_HTML_Doctype_Info instance will be returned if the
* provided DOCTYPE HTML is a valid DOCTYPE. Otherwise, null.
*/
public static function from_doctype_token( string $doctype_html ): ?self {
$doctype_name = null;
$doctype_public_id = null;
$doctype_system_id = null;
$end = strlen( $doctype_html ) - 1;
/*
* This parser combines the rules for parsing DOCTYPE tokens found in the HTML
* specification for the DOCTYPE related tokenizer states.
*
* @see https://html.spec.whatwg.org/#doctype-state
*/
/*
* - Valid DOCTYPE HTML token must be at least `` assuming a complete token not
* ending in end-of-file.
* - It must start with an ASCII case-insensitive match for `` must be the final byte in the HTML string.
*/
if (
$end < 9 ||
0 !== substr_compare( $doctype_html, '`?
if ( '>' !== $doctype_html[ $end ] || ( strcspn( $doctype_html, '>', $at ) + $at ) < $end ) {
return null;
}
/*
* Perform newline normalization and ensure the $end value is correct after normalization.
*
* @see https://html.spec.whatwg.org/#preprocessing-the-input-stream
* @see https://infra.spec.whatwg.org/#normalize-newlines
*/
$doctype_html = str_replace( "\r\n", "\n", $doctype_html );
$doctype_html = str_replace( "\r", "\n", $doctype_html );
$end = strlen( $doctype_html ) - 1;
/*
* In this state, the doctype token has been found and its "content" optionally including the
* name, public identifier, and system identifier is between the current position and the end.
*
* ""
* ╰─ $at ╰─ $end
*
* It's also possible that the declaration part is empty.
*
* â•─ $at
* ""
* ╰─ $end
*
* Rules for parsing ">" which terminates the DOCTYPE do not need to be considered as they
* have been handled above in the condition that the provided DOCTYPE HTML must contain
* exactly one ">" character in the final position.
*/
/*
*
* Parsing effectively begins in "Before DOCTYPE name state". Ignore whitespace and
* proceed to the next state.
*
* @see https://html.spec.whatwg.org/#before-doctype-name-state
*/
$at += strspn( $doctype_html, " \t\n\f\r", $at );
if ( $at >= $end ) {
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, true );
}
$name_length = strcspn( $doctype_html, " \t\n\f\r", $at, $end - $at );
$doctype_name = str_replace( "\0", "\u{FFFD}", strtolower( substr( $doctype_html, $at, $name_length ) ) );
$at += $name_length;
$at += strspn( $doctype_html, " \t\n\f\r", $at, $end - $at );
if ( $at >= $end ) {
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, false );
}
/*
* "After DOCTYPE name state"
*
* Find a case-insensitive match for "PUBLIC" or "SYSTEM" at this point.
* Otherwise, set force-quirks and enter bogus DOCTYPE state (skip the rest of the doctype).
*
* @see https://html.spec.whatwg.org/#after-doctype-name-state
*/
if ( $at + 6 >= $end ) {
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, true );
}
/*
* > If the six characters starting from the current input character are an ASCII
* > case-insensitive match for the word "PUBLIC", then consume those characters
* > and switch to the after DOCTYPE public keyword state.
*/
if ( 0 === substr_compare( $doctype_html, 'PUBLIC', $at, 6, true ) ) {
$at += 6;
$at += strspn( $doctype_html, " \t\n\f\r", $at, $end - $at );
if ( $at >= $end ) {
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, true );
}
goto parse_doctype_public_identifier;
}
/*
* > Otherwise, if the six characters starting from the current input character are an ASCII
* > case-insensitive match for the word "SYSTEM", then consume those characters and switch
* > to the after DOCTYPE system keyword state.
*/
if ( 0 === substr_compare( $doctype_html, 'SYSTEM', $at, 6, true ) ) {
$at += 6;
$at += strspn( $doctype_html, " \t\n\f\r", $at, $end - $at );
if ( $at >= $end ) {
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, true );
}
goto parse_doctype_system_identifier;
}
/*
* > Otherwise, this is an invalid-character-sequence-after-doctype-name parse error.
* > Set the current DOCTYPE token's force-quirks flag to on. Reconsume in the bogus
* > DOCTYPE state.
*/
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, true );
parse_doctype_public_identifier:
/*
* The parser should enter "DOCTYPE public identifier (double-quoted) state" or
* "DOCTYPE public identifier (single-quoted) state" by finding one of the valid quotes.
* Anything else forces quirks mode and ignores the rest of the contents.
*
* @see https://html.spec.whatwg.org/#doctype-public-identifier-(double-quoted)-state
* @see https://html.spec.whatwg.org/#doctype-public-identifier-(single-quoted)-state
*/
$closer_quote = $doctype_html[ $at ];
/*
* > This is a missing-quote-before-doctype-public-identifier parse error. Set the
* > current DOCTYPE token's force-quirks flag to on. Reconsume in the bogus DOCTYPE state.
*/
if ( '"' !== $closer_quote && "'" !== $closer_quote ) {
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, true );
}
++$at;
$identifier_length = strcspn( $doctype_html, $closer_quote, $at, $end - $at );
$doctype_public_id = str_replace( "\0", "\u{FFFD}", substr( $doctype_html, $at, $identifier_length ) );
$at += $identifier_length;
if ( $at >= $end || $closer_quote !== $doctype_html[ $at ] ) {
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, true );
}
++$at;
/*
* "Between DOCTYPE public and system identifiers state"
*
* Advance through whitespace between public and system identifiers.
*
* @see https://html.spec.whatwg.org/#between-doctype-public-and-system-identifiers-state
*/
$at += strspn( $doctype_html, " \t\n\f\r", $at, $end - $at );
if ( $at >= $end ) {
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, false );
}
parse_doctype_system_identifier:
/*
* The parser should enter "DOCTYPE system identifier (double-quoted) state" or
* "DOCTYPE system identifier (single-quoted) state" by finding one of the valid quotes.
* Anything else forces quirks mode and ignores the rest of the contents.
*
* @see https://html.spec.whatwg.org/#doctype-system-identifier-(double-quoted)-state
* @see https://html.spec.whatwg.org/#doctype-system-identifier-(single-quoted)-state
*/
$closer_quote = $doctype_html[ $at ];
/*
* > This is a missing-quote-before-doctype-system-identifier parse error. Set the
* > current DOCTYPE token's force-quirks flag to on. Reconsume in the bogus DOCTYPE state.
*/
if ( '"' !== $closer_quote && "'" !== $closer_quote ) {
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, true );
}
++$at;
$identifier_length = strcspn( $doctype_html, $closer_quote, $at, $end - $at );
$doctype_system_id = str_replace( "\0", "\u{FFFD}", substr( $doctype_html, $at, $identifier_length ) );
$at += $identifier_length;
if ( $at >= $end || $closer_quote !== $doctype_html[ $at ] ) {
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, true );
}
return new self( $doctype_name, $doctype_public_id, $doctype_system_id, false );
}
}
PK <»–[±FœM ! class-wp-html-attribute-token.phpnu „[µü¤ name = $name;
$this->value_starts_at = $value_start;
$this->value_length = $value_length;
$this->start = $start;
$this->end = $end;
$this->is_true = $is_true;
}
}
PK <»–[,M÷
class-wp-html-span.phpnu „[µü¤ start = $start;
$this->end = $end;
}
}
PK <»–[P°&D D ' class-wp-html-unsupported-exception.phpnu „[µü¤ Initially, the stack of open elements is empty. The stack grows
* > downwards; the topmost node on the stack is the first one added
* > to the stack, and the bottommost node of the stack is the most
* > recently added node in the stack (notwithstanding when the stack
* > is manipulated in a random access fashion as part of the handling
* > for misnested tags).
*
* @since 6.4.0
*
* @access private
*
* @see https://html.spec.whatwg.org/#stack-of-open-elements
* @see WP_HTML_Processor
*/
class WP_HTML_Open_Elements {
/**
* Holds the stack of open element references.
*
* @since 6.4.0
*
* @var WP_HTML_Token[]
*/
public $stack = array();
/**
* Whether a P element is in button scope currently.
*
* This class optimizes scope lookup by pre-calculating
* this value when elements are added and removed to the
* stack of open elements which might change its value.
* This avoids frequent iteration over the stack.
*
* @since 6.4.0
*
* @var bool
*/
private $has_p_in_button_scope = false;
/**
* Reports if a specific node is in the stack of open elements.
*
* @since 6.4.0
*
* @param WP_HTML_Token $token Look for this node in the stack.
* @return bool Whether the referenced node is in the stack of open elements.
*/
public function contains_node( $token ) {
foreach ( $this->walk_up() as $item ) {
if ( $token->bookmark_name === $item->bookmark_name ) {
return true;
}
}
return false;
}
/**
* Returns how many nodes are currently in the stack of open elements.
*
* @since 6.4.0
*
* @return int How many node are in the stack of open elements.
*/
public function count() {
return count( $this->stack );
}
/**
* Returns the node at the end of the stack of open elements,
* if one exists. If the stack is empty, returns null.
*
* @since 6.4.0
*
* @return WP_HTML_Token|null Last node in the stack of open elements, if one exists, otherwise null.
*/
public function current_node() {
$current_node = end( $this->stack );
return $current_node ? $current_node : null;
}
/**
* Returns whether an element is in a specific scope.
*
* ## HTML Support
*
* This function skips checking for the termination list because there
* are no supported elements which appear in the termination list.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#has-an-element-in-the-specific-scope
*
* @param string $tag_name Name of tag check.
* @param string[] $termination_list List of elements that terminate the search.
* @return bool Whether the element was found in a specific scope.
*/
public function has_element_in_specific_scope( $tag_name, $termination_list ) {
foreach ( $this->walk_up() as $node ) {
if ( $node->node_name === $tag_name ) {
return true;
}
switch ( $node->node_name ) {
case 'HTML':
return false;
}
if ( in_array( $node->node_name, $termination_list, true ) ) {
return true;
}
}
return false;
}
/**
* Returns whether a particular element is in scope.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#has-an-element-in-scope
*
* @param string $tag_name Name of tag to check.
* @return bool Whether given element is in scope.
*/
public function has_element_in_scope( $tag_name ) {
return $this->has_element_in_specific_scope(
$tag_name,
array(
/*
* Because it's not currently possible to encounter
* one of the termination elements, they don't need
* to be listed here. If they were, they would be
* unreachable and only waste CPU cycles while
* scanning through HTML.
*/
)
);
}
/**
* Returns whether a particular element is in list item scope.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#has-an-element-in-list-item-scope
*
* @throws WP_HTML_Unsupported_Exception Always until this function is implemented.
*
* @param string $tag_name Name of tag to check.
* @return bool Whether given element is in scope.
*/
public function has_element_in_list_item_scope( $tag_name ) {
throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on list item scope.' );
return false; // The linter requires this unreachable code until the function is implemented and can return.
}
/**
* Returns whether a particular element is in button scope.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#has-an-element-in-button-scope
*
* @param string $tag_name Name of tag to check.
* @return bool Whether given element is in scope.
*/
public function has_element_in_button_scope( $tag_name ) {
return $this->has_element_in_specific_scope( $tag_name, array( 'BUTTON' ) );
}
/**
* Returns whether a particular element is in table scope.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#has-an-element-in-table-scope
*
* @throws WP_HTML_Unsupported_Exception Always until this function is implemented.
*
* @param string $tag_name Name of tag to check.
* @return bool Whether given element is in scope.
*/
public function has_element_in_table_scope( $tag_name ) {
throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on table scope.' );
return false; // The linter requires this unreachable code until the function is implemented and can return.
}
/**
* Returns whether a particular element is in select scope.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#has-an-element-in-select-scope
*
* @throws WP_HTML_Unsupported_Exception Always until this function is implemented.
*
* @param string $tag_name Name of tag to check.
* @return bool Whether given element is in scope.
*/
public function has_element_in_select_scope( $tag_name ) {
throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on select scope.' );
return false; // The linter requires this unreachable code until the function is implemented and can return.
}
/**
* Returns whether a P is in BUTTON scope.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#has-an-element-in-button-scope
*
* @return bool Whether a P is in BUTTON scope.
*/
public function has_p_in_button_scope() {
return $this->has_p_in_button_scope;
}
/**
* Pops a node off of the stack of open elements.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#stack-of-open-elements
*
* @return bool Whether a node was popped off of the stack.
*/
public function pop() {
$item = array_pop( $this->stack );
if ( null === $item ) {
return false;
}
$this->after_element_pop( $item );
return true;
}
/**
* Pops nodes off of the stack of open elements until one with the given tag name has been popped.
*
* @since 6.4.0
*
* @see WP_HTML_Open_Elements::pop
*
* @param string $tag_name Name of tag that needs to be popped off of the stack of open elements.
* @return bool Whether a tag of the given name was found and popped off of the stack of open elements.
*/
public function pop_until( $tag_name ) {
foreach ( $this->walk_up() as $item ) {
$this->pop();
if ( $tag_name === $item->node_name ) {
return true;
}
}
return false;
}
/**
* Pushes a node onto the stack of open elements.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#stack-of-open-elements
*
* @param WP_HTML_Token $stack_item Item to add onto stack.
*/
public function push( $stack_item ) {
$this->stack[] = $stack_item;
$this->after_element_push( $stack_item );
}
/**
* Removes a specific node from the stack of open elements.
*
* @since 6.4.0
*
* @param WP_HTML_Token $token The node to remove from the stack of open elements.
* @return bool Whether the node was found and removed from the stack of open elements.
*/
public function remove_node( $token ) {
foreach ( $this->walk_up() as $position_from_end => $item ) {
if ( $token->bookmark_name !== $item->bookmark_name ) {
continue;
}
$position_from_start = $this->count() - $position_from_end - 1;
array_splice( $this->stack, $position_from_start, 1 );
$this->after_element_pop( $item );
return true;
}
return false;
}
/**
* Steps through the stack of open elements, starting with the top element
* (added first) and walking downwards to the one added last.
*
* This generator function is designed to be used inside a "foreach" loop.
*
* Example:
*
* $html = 'We are here';
* foreach ( $stack->walk_down() as $node ) {
* echo "{$node->node_name} -> ";
* }
* > EM -> STRONG -> A ->
*
* To start with the most-recently added element and walk towards the top,
* see WP_HTML_Open_Elements::walk_up().
*
* @since 6.4.0
*/
public function walk_down() {
$count = count( $this->stack );
for ( $i = 0; $i < $count; $i++ ) {
yield $this->stack[ $i ];
}
}
/**
* Steps through the stack of open elements, starting with the bottom element
* (added last) and walking upwards to the one added first.
*
* This generator function is designed to be used inside a "foreach" loop.
*
* Example:
*
* $html = 'We are here';
* foreach ( $stack->walk_up() as $node ) {
* echo "{$node->node_name} -> ";
* }
* > A -> STRONG -> EM ->
*
* To start with the first added element and walk towards the bottom,
* see WP_HTML_Open_Elements::walk_down().
*
* @since 6.4.0
*/
public function walk_up() {
for ( $i = count( $this->stack ) - 1; $i >= 0; $i-- ) {
yield $this->stack[ $i ];
}
}
/*
* Internal helpers.
*/
/**
* Updates internal flags after adding an element.
*
* Certain conditions (such as "has_p_in_button_scope") are maintained here as
* flags that are only modified when adding and removing elements. This allows
* the HTML Processor to quickly check for these conditions instead of iterating
* over the open stack elements upon each new tag it encounters. These flags,
* however, need to be maintained as items are added and removed from the stack.
*
* @since 6.4.0
*
* @param WP_HTML_Token $item Element that was added to the stack of open elements.
*/
public function after_element_push( $item ) {
/*
* When adding support for new elements, expand this switch to trap
* cases where the precalculated value needs to change.
*/
switch ( $item->node_name ) {
case 'BUTTON':
$this->has_p_in_button_scope = false;
break;
case 'P':
$this->has_p_in_button_scope = true;
break;
}
}
/**
* Updates internal flags after removing an element.
*
* Certain conditions (such as "has_p_in_button_scope") are maintained here as
* flags that are only modified when adding and removing elements. This allows
* the HTML Processor to quickly check for these conditions instead of iterating
* over the open stack elements upon each new tag it encounters. These flags,
* however, need to be maintained as items are added and removed from the stack.
*
* @since 6.4.0
*
* @param WP_HTML_Token $item Element that was removed from the stack of open elements.
*/
public function after_element_pop( $item ) {
/*
* When adding support for new elements, expand this switch to trap
* cases where the precalculated value needs to change.
*/
switch ( $item->node_name ) {
case 'BUTTON':
$this->has_p_in_button_scope = $this->has_element_in_button_scope( 'P' );
break;
case 'P':
$this->has_p_in_button_scope = $this->has_element_in_button_scope( 'P' );
break;
}
}
}
PK <»–[MzW8b¶ b¶ class-wp-html-processor.phpnu „[µü¤ next_tag( array( 'breadcrumbs' => array( 'DIV', 'FIGURE', 'IMG' ) ) ) ) {
* $processor->add_class( 'responsive-image' );
* }
*
* #### Breadcrumbs
*
* Breadcrumbs represent the stack of open elements from the root
* of the document or fragment down to the currently-matched node,
* if one is currently selected. Call WP_HTML_Processor::get_breadcrumbs()
* to inspect the breadcrumbs for a matched tag.
*
* Breadcrumbs can specify nested HTML structure and are equivalent
* to a CSS selector comprising tag names separated by the child
* combinator, such as "DIV > FIGURE > IMG".
*
* Since all elements find themselves inside a full HTML document
* when parsed, the return value from `get_breadcrumbs()` will always
* contain any implicit outermost elements. For example, when parsing
* with `create_fragment()` in the `BODY` context (the default), any
* tag in the given HTML document will contain `array( 'HTML', 'BODY', … )`
* in its breadcrumbs.
*
* Despite containing the implied outermost elements in their breadcrumbs,
* tags may be found with the shortest-matching breadcrumb query. That is,
* `array( 'IMG' )` matches all IMG elements and `array( 'P', 'IMG' )`
* matches all IMG elements directly inside a P element. To ensure that no
* partial matches erroneously match it's possible to specify in a query
* the full breadcrumb match all the way down from the root HTML element.
*
* Example:
*
* $html = 'A lovely day outside';
* // ----- Matches here.
* $processor->next_tag( array( 'breadcrumbs' => array( 'FIGURE', 'IMG' ) ) );
*
* $html = 'A lovely day outside';
* // ---- Matches here.
* $processor->next_tag( array( 'breadcrumbs' => array( 'FIGURE', 'FIGCAPTION', 'EM' ) ) );
*
* $html = '