[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/html-api/ -> class-wp-html-open-elements.php (summary)

HTML API: WP_HTML_Open_Elements class

File Size: 852 lines (22 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_HTML_Open_Elements:: (27 methods):
  set_pop_handler()
  set_push_handler()
  at()
  contains()
  contains_node()
  count()
  current_node()
  current_node_is()
  has_element_in_specific_scope()
  has_element_in_scope()
  has_element_in_list_item_scope()
  has_element_in_button_scope()
  has_element_in_table_scope()
  has_element_in_select_scope()
  has_p_in_button_scope()
  pop()
  pop_until()
  push()
  remove_node()
  walk_down()
  walk_up()
  after_element_push()
  after_element_pop()
  clear_to_table_context()
  clear_to_table_body_context()
  clear_to_table_row_context()
  __wakeup()


Class: WP_HTML_Open_Elements  - X-Ref

Core class used by the HTML processor during HTML parsing
for managing the stack of open elements.

This class is designed for internal use by the HTML processor.

> 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).

set_pop_handler( Closure $handler )   X-Ref
Sets a pop handler that will be called when an item is popped off the stack of
open elements.

The function will be called with the pushed item as its argument.

param: Closure $handler The handler function.

set_push_handler( Closure $handler )   X-Ref
Sets a push handler that will be called when an item is pushed onto the stack of
open elements.

The function will be called with the pushed item as its argument.

param: Closure $handler The handler function.

at( int $nth )   X-Ref
Returns the name of the node at the nth position on the stack
of open elements, or `null` if no such position exists.

Note that this uses a 1-based index, which represents the
"nth item" on the stack, counting from the top, where the
top-most element is the 1st, the second is the 2nd, etc...

param: int $nth Retrieve the nth item on the stack, with 1 being
return: WP_HTML_Token|null Name of the node on the stack at the given location,

contains( string $node_name )   X-Ref
Reports if a node of a given name is in the stack of open elements.

param: string $node_name Name of node for which to check.
return: bool Whether a node of the given name is in the stack of open elements.

contains_node( WP_HTML_Token $token )   X-Ref
Reports if a specific node is in the stack of open elements.

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.

count()   X-Ref
Returns how many nodes are currently in the stack of open elements.

return: int How many node are in the stack of open elements.

current_node()   X-Ref
Returns the node at the end of the stack of open elements,
if one exists. If the stack is empty, returns null.

return: WP_HTML_Token|null Last node in the stack of open elements, if one exists, otherwise null.

current_node_is( string $identity )   X-Ref
Indicates if the current node is of a given type or name.

It's possible to pass either a node type or a node name to this function.
In the case there is no current element it will always return `false`.

Example:

// Is the current node a text node?
$stack->current_node_is( '#text' );

// Is the current node a DIV element?
$stack->current_node_is( 'DIV' );

// Is the current node any element/tag?
$stack->current_node_is( '#tag' );

param: string $identity Check if the current node has this name or type (depending on what is provided).
return: bool Whether there is a current element that matches the given identity, whether a token name or type.

has_element_in_specific_scope( string $tag_name, $termination_list )   X-Ref
Returns whether an element is in a 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.

has_element_in_scope( string $tag_name )   X-Ref
Returns whether a particular element is in scope.

> The stack of open elements is said to have a particular element in
> scope when it has that element in the specific scope consisting of
> the following element types:
>
>   - applet
>   - caption
>   - html
>   - table
>   - td
>   - th
>   - marquee
>   - object
>   - template
>   - MathML mi
>   - MathML mo
>   - MathML mn
>   - MathML ms
>   - MathML mtext
>   - MathML annotation-xml
>   - SVG foreignObject
>   - SVG desc
>   - SVG title

param: string $tag_name Name of tag to check.
return: bool Whether given element is in scope.

has_element_in_list_item_scope( string $tag_name )   X-Ref
Returns whether a particular element is in list item scope.

> The stack of open elements is said to have a particular element
> in list item scope when it has that element in the specific scope
> consisting of the following element types:
>
>   - All the element types listed above for the has an element in scope algorithm.
>   - ol in the HTML namespace
>   - ul in the HTML namespace

param: string $tag_name Name of tag to check.
return: bool Whether given element is in scope.

has_element_in_button_scope( string $tag_name )   X-Ref
Returns whether a particular element is in button scope.

> The stack of open elements is said to have a particular element
> in button scope when it has that element in the specific scope
> consisting of the following element types:
>
>   - All the element types listed above for the has an element in scope algorithm.
>   - button in the HTML namespace

param: string $tag_name Name of tag to check.
return: bool Whether given element is in scope.

has_element_in_table_scope( string $tag_name )   X-Ref
Returns whether a particular element is in table scope.

> The stack of open elements is said to have a particular element
> in table scope when it has that element in the specific scope
> consisting of the following element types:
>
>   - html in the HTML namespace
>   - table in the HTML namespace
>   - template in the HTML namespace

param: string $tag_name Name of tag to check.
return: bool Whether given element is in scope.

has_element_in_select_scope( string $tag_name )   X-Ref
Returns whether a particular element is in select scope.

This test differs from the others like it, in that its rules are inverted.
Instead of arriving at a match when one of any tag in a termination group
is reached, this one terminates if any other tag is reached.

> The stack of open elements is said to have a particular element in select scope when it has
> that element in the specific scope consisting of all element types except the following:
>   - optgroup in the HTML namespace
>   - option in the HTML namespace

param: string $tag_name Name of tag to check.
return: bool Whether the given element is in SELECT scope.

has_p_in_button_scope()   X-Ref
Returns whether a P is in BUTTON scope.

return: bool Whether a P is in BUTTON scope.

pop()   X-Ref
Pops a node off of the stack of open elements.

return: bool Whether a node was popped off of the stack.

pop_until( string $html_tag_name )   X-Ref
Pops nodes off of the stack of open elements until an HTML tag with the given name has been popped.

param: string $html_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.

push( WP_HTML_Token $stack_item )   X-Ref
Pushes a node onto the stack of open elements.

param: WP_HTML_Token $stack_item Item to add onto stack.

remove_node( WP_HTML_Token $token )   X-Ref
Removes a specific node from the stack of open elements.

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.

walk_down()   X-Ref
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 = '<em><strong><a>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().


walk_up( ?WP_HTML_Token $above_this_node = null )   X-Ref
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 = '<em><strong><a>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().

param: WP_HTML_Token|null $above_this_node Optional. Start traversing above this node,

after_element_push( WP_HTML_Token $item )   X-Ref
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.

param: WP_HTML_Token $item Element that was added to the stack of open elements.

after_element_pop( WP_HTML_Token $item )   X-Ref
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.

param: WP_HTML_Token $item Element that was removed from the stack of open elements.

clear_to_table_context()   X-Ref
Clear the stack back to a table context.

> When the steps above require the UA to clear the stack back to a table context, it means
> that the UA must, while the current node is not a table, template, or html element, pop
> elements from the stack of open elements.


clear_to_table_body_context()   X-Ref
Clear the stack back to a table body context.

> When the steps above require the UA to clear the stack back to a table body context, it
> means that the UA must, while the current node is not a tbody, tfoot, thead, template, or
> html element, pop elements from the stack of open elements.


clear_to_table_row_context()   X-Ref
Clear the stack back to a table row context.

> When the steps above require the UA to clear the stack back to a table row context, it
> means that the UA must, while the current node is not a tr, template, or html element, pop
> elements from the stack of open elements.


__wakeup()   X-Ref
Wakeup magic method.




Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref