Indicates if the currently-matched node expects a closing token, or if it will self-close on the next step.
Description
Most HTML elements expect a closer, such as a P element or a DIV element. Others, like an IMG element are void and don’t have a closing tag. Special elements, such as SCRIPT and STYLE, are treated just like void tags. Text nodes and self-closing foreign content will also act just like a void tag, immediately closing as soon as the processor advances to the next token.
Parameters
$nodeWP_HTML_Token|nulloptional- Node to examine, if provided.
Default is to examine current node.Default:
null
Source
public function expects_closer( ?WP_HTML_Token $node = null ): ?bool {
$token_name = $node->node_name ?? $this->get_token_name();
if ( ! isset( $token_name ) ) {
return null;
}
$token_namespace = $node->namespace ?? $this->get_namespace();
$token_has_self_closing = $node->has_self_closing_flag ?? $this->has_self_closing_flag();
return ! (
// Comments, text nodes, and other atomic tokens.
'#' === $token_name[0] ||
// Doctype declarations.
'html' === $token_name ||
// Void elements.
( 'html' === $token_namespace && self::is_void( $token_name ) ) ||
// Special atomic elements.
( 'html' === $token_namespace && in_array( $token_name, array( 'IFRAME', 'NOEMBED', 'NOFRAMES', 'SCRIPT', 'STYLE', 'TEXTAREA', 'TITLE', 'XMP' ), true ) ) ||
// Self-closing elements in foreign content.
( 'html' !== $token_namespace && $token_has_self_closing )
);
}
Changelog
| Version | Description |
|---|---|
| 6.6.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.