Indicates the kind of matched token, if any.
Description
This differs from get_token_name() in that it always returns a static string indicating the type, whereas get_token_name() may return values derived from the token itself, such as a tag name or processing instruction tag.
Possible values:
#tagwhen matched on a tag.#textwhen matched on a text node.#cdata-sectionwhen matched on a CDATA node.#commentwhen matched on a comment.#doctypewhen matched on a DOCTYPE declaration.#presumptuous-tagwhen matched on an empty tag closer.#funky-commentwhen matched on a funky comment.#processing-instructionwhen matched on a processing instruction.
Source
public function get_token_type(): ?string {
if ( $this->is_virtual() ) {
/*
* This logic comes from the Tag Processor.
*
* @todo It would be ideal not to repeat this here, but it's not clearly
* better to allow passing a token name to `get_token_type()`.
*/
$node_name = $this->current_element->token->node_name;
$starting_char = $node_name[0];
if ( 'A' <= $starting_char && 'Z' >= $starting_char ) {
return '#tag';
}
if ( 'html' === $node_name ) {
return '#doctype';
}
return $node_name;
}
return parent::get_token_type();
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.