Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment to connect HTML attributes with custom fields #53514

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 62 additions & 13 deletions lib/compat/wordpress-6.4/html-api/class-wp-html-open-elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ class WP_HTML_Open_Elements {
*/
public $stack = array();

/**
* Holds functions added to be called after popping an element off the stack.
*
* Listeners are passed the WP_HTML_Token for the item that was removed.
*
* @since 6.4.0
*
* @var array
*/
private $after_pop_listeners = array();

/**
* Whether a P element is in button scope currently.
*
Expand Down Expand Up @@ -119,6 +130,15 @@ public function has_element_in_specific_scope( $tag_name, $termination_list ) {
if ( $node->node_name === $tag_name ) {
return true;
}

switch ( $node->node_name ) {
case 'HTML':
return false;
}

if ( in_array( $node->node_name, $termination_list, true ) ) {
return true;
}
}

return false;
Expand All @@ -135,19 +155,7 @@ public function has_element_in_specific_scope( $tag_name, $termination_list ) {
* @return bool Whether given element is in scope.
*/
public function has_element_in_scope( $tag_name ) {
return $this->has_element_in_specific_scope(
$tag_name,
array(

/*
* Because it's not currently possible to encounter
* one of the termination elements, they don't need
* to be listed here. If they were, they would be
* unreachable and only waste CPU cycles while
* scanning through HTML.
*/
)
);
return $this->has_element_in_specific_scope( $tag_name, array( 'BUTTON' ) );
}

/**
Expand Down Expand Up @@ -398,6 +406,10 @@ public function after_element_push( $item ) {
* cases where the precalculated value needs to change.
*/
switch ( $item->node_name ) {
case 'BUTTON':
$this->has_p_in_button_scope = false;
break;

case 'P':
$this->has_p_in_button_scope = true;
break;
Expand All @@ -423,9 +435,46 @@ public function after_element_pop( $item ) {
* cases where the precalculated value needs to change.
*/
switch ( $item->node_name ) {
case 'BUTTON':
$this->has_p_in_button_scope = $this->has_element_in_button_scope( 'P' );
break;

case 'P':
$this->has_p_in_button_scope = $this->has_element_in_button_scope( 'P' );
break;
}

// Call any listeners that are registered.
foreach ( $this->after_pop_listeners as $listener ) {
call_user_func( $listener, $item );
}
}
/**
* Creates a context in which a given listener is called after
* popping an element off of the stack of open elements.
*
* It's unlikely that you will need this function. It exists
* to aid an optimization in the `WP_HTML_Processor` and the
* strange form of calling a generator inside a `foreach`
* loop ensures that proper cleanup of the listener occurs.
*
* Example:
*
* $did_close = false;
* $closed_a_p = function ( $item ) use ( &$did_close ) { $did_close = 'P' === $item->node_name; };
* foreach ( $stack_of_open_elements->with_pop_listener( $closed_a_p ) ) {
* while ( ! $did_close && $processor->next_tag() ) {
* // This loop executes until _any_ P element is closed.
* }
* }
*
* @since 6.4.0
*
* @param callable $listener Called with the WP_HTML_Token for the item that was popped off of the stack.
*/
public function with_pop_listener( $listener ) {
$this->after_pop_listeners[] = $listener;
yield;
array_pop( $this->after_pop_listeners );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ class WP_HTML_Processor_State {
*/
public $context_node = null;


/**
* The frameset-ok flag indicates if a `FRAMESET` element is allowed in the current state.
*
* > The frameset-ok flag is set to "ok" when the parser is created. It is set to "not ok" after certain tokens are seen.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#frameset-ok-flag
*
* @var bool
*/
public $frameset_ok = true;

/**
* Constructor - creates a new and empty state value.
*
Expand Down
Loading