Parses tag query input into internal search criteria.
Parameters
$query
array|string|nulloptional- Which tag name to find, having which class, etc. Default is to find any tag.
tag_name
string|nullWhich tag to find, ornull
for "any tag."match_offset
int|nullFind the Nth tag matching all search criteria.
1 for "first" tag, 3 for "third," etc.
Defaults to first tag.class_name
string|nullTag must contain this class name to match.tag_closers
string"visit" or "skip": whether to stop on tag closers, e.g. </div>.
Source
*
* @return bool Whether the current tag is a tag closer.
*/
public function is_tag_closer(): bool {
return (
self::STATE_MATCHED_TAG === $this->parser_state &&
$this->is_closing_tag &&
/*
* The BR tag can only exist as an opening tag. If something like `</br>`
* appears then the HTML parser will treat it as an opening tag with no
* attributes. The BR tag is unique in this way.
*
* @see https://html.spec.whatwg.org/#parsing-main-inbody
*/
'BR' !== $this->get_tag()
);
}
/**
* Indicates the kind of matched token, if any.
*
* 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:
* - `#tag` when matched on a tag.
* - `#text` when matched on a text node.
* - `#cdata-section` when matched on a CDATA node.
* - `#comment` when matched on a comment.
* - `#doctype` when matched on a DOCTYPE declaration.
* - `#presumptuous-tag` when matched on an empty tag closer.
* - `#funky-comment` when matched on a funky comment.
*
* @since 6.5.0
*
* @return string|null What kind of token is matched, or null.
*/
public function get_token_type(): ?string {
switch ( $this->parser_state ) {
case self::STATE_MATCHED_TAG:
return '#tag';
case self::STATE_DOCTYPE:
return '#doctype';
Changelog
Version | Description |
---|---|
6.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.