WP_HTML_Active_Formatting_Elements
- Since
- 6.4.0
- Source
wp-includes/html-api/class-wp-html-active-formatting-elements.php:37
Description
This class is designed for internal use by the HTML processor.
Initially, the list of active formatting elements is empty.
It is used to handle mis-nested formatting element tags.The list contains elements in the formatting category, and markers.
The markers are inserted when entering applet, object, marquee, template, td, th, and caption elements, and are used to prevent formatting from "leaking" into applet, object, marquee, template, td, th, and caption elements.In addition, each element in the list of active formatting elements is associated with the token for which it was created, so that further elements can be created for that token if necessary.
Compatibility
- WordPress
- since 6.4.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Properties · 1
$stackWP_HTML_Token[]private- Holds the stack of active formatting element references.
Methods · 9
- contains_node()Reports if a specific node is in the stack of active formatting elements.
- count()Returns how many nodes are currently in the stack of active formatting elements.
- current_node()Returns the node at the end of the stack of active formatting elements, if one exists. If the stack is empty, returns null.
- insert_marker()Inserts a "marker" at the end of the list of active formatting elements.
- push()Pushes a node onto the stack of active formatting elements.
- remove_node()Removes a node from the stack of active formatting elements.
- walk_down()Steps through the stack of active formatting elements, starting with the top element (added first) and walking downwards to the one added last.
- walk_up()Steps through the stack of active formatting elements, starting with the bottom element (added last) and walking upwards to the one added first.
- clear_up_to_last_marker()Clears the list of active formatting elements up to the last marker.
Source code
class WP_HTML_Active_Formatting_Elements { /** * Holds the stack of active formatting element references. * * @since 6.4.0 * * @var WP_HTML_Token[] */ private $stack = array(); /** * Reports if a specific node is in the stack of active formatting 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 active formatting elements. */ public function contains_node( WP_HTML_Token $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 active formatting elements. * * @since 6.4.0 * * @return int How many nodes are in the stack of active formatting elements. */ public function count() { return count( $this->stack ); } /** * Returns the node at the end of the stack of active formatting 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 active formatting elements, if one exists, otherwise null. */ public function current_node() { $current_node = end( $this->stack ); return $current_node ? $current_node : null; } /** * Inserts a "marker" at the end of the list of active formatting elements. * * > The markers are inserted when entering applet, object, marquee, * > template, td, th, and caption elements, and are used to prevent * > formatting from "leaking" into applet, object, marquee, template, * > td, th, and caption elements. * * @see https://html.spec.whatwg.org/#concept-parser-marker * * @since 6.7.0 */ public function insert_marker(): void { $this->push( new WP_HTML_Token( null, 'marker', false ) ); } /** * Pushes a node onto the stack of active formatting elements. * * @since 6.4.0 * * @see https://html.spec.whatwg.org/#push-onto-the-list-of-active-formatting-elements * * @param WP_HTML_Token $token Push this node onto the stack. */ public function push( WP_HTML_Token $token ) { /*Changelog
Introduced in 6.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/html-api/class-wp-html-active-formatting-elements.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.