@@ -442,7 +442,7 @@ private function bail( string $message ) {
442442
443443 $ active_formats = array ();
444444 foreach ( $ this ->state ->active_formatting_elements ->walk_down () as $ item ) {
445- $ active_formats [] = $ item-> node_name ;
445+ $ active_formats [] = $ item instanceof AFE_Marker ? ' (marker) ' : $ item -> tag_name ;
446446 }
447447
448448 $ this ->last_error = self ::ERROR_UNSUPPORTED ;
@@ -2350,10 +2350,10 @@ private function step_in_body(): bool {
23502350 */
23512351 case '+A ' :
23522352 foreach ( $ this ->state ->active_formatting_elements ->walk_up () as $ item ) {
2353- switch ( $ item-> node_name ) {
2354- case ' marker ' :
2355- break ;
2356-
2353+ if ( $ item instanceof AFE_Marker ) {
2354+ break ;
2355+ }
2356+ switch ( $ item -> tag_name ) {
23572357 case 'A ' :
23582358 $ this ->run_adoption_agency_algorithm ();
23592359 $ this ->state ->active_formatting_elements ->remove_node ( $ item );
@@ -2364,7 +2364,7 @@ private function step_in_body(): bool {
23642364
23652365 $ this ->reconstruct_active_formatting_elements ();
23662366 $ this ->insert_html_element ( $ this ->state ->current_token );
2367- $ this ->state -> active_formatting_elements -> push ( $ this ->state ->current_token );
2367+ $ this ->push_active_formatting_element ( $ this ->state ->current_token );
23682368 return true ;
23692369
23702370 /*
@@ -2385,7 +2385,7 @@ private function step_in_body(): bool {
23852385 case '+U ' :
23862386 $ this ->reconstruct_active_formatting_elements ();
23872387 $ this ->insert_html_element ( $ this ->state ->current_token );
2388- $ this ->state -> active_formatting_elements -> push ( $ this ->state ->current_token );
2388+ $ this ->push_active_formatting_element ( $ this ->state ->current_token );
23892389 return true ;
23902390
23912391 /*
@@ -2401,7 +2401,7 @@ private function step_in_body(): bool {
24012401 }
24022402
24032403 $ this ->insert_html_element ( $ this ->state ->current_token );
2404- $ this ->state -> active_formatting_elements -> push ( $ this ->state ->current_token );
2404+ $ this ->push_active_formatting_element ( $ this ->state ->current_token );
24052405 return true ;
24062406
24072407 /*
@@ -5121,7 +5121,7 @@ public function seek( $bookmark_name ): bool {
51215121 }
51225122
51235123 foreach ( $ this ->state ->active_formatting_elements ->walk_up () as $ item ) {
5124- if ( 'context-node ' === $ item ->bookmark_name ) {
5124+ if ( 'context-node ' === $ item ->token -> bookmark_name ) {
51255125 break ;
51265126 }
51275127
@@ -5401,8 +5401,8 @@ private function reconstruct_active_formatting_elements(): bool {
54015401 * > elements, then there is nothing to reconstruct; stop this algorithm.
54025402 */
54035403 if (
5404- ' marker ' === $ last_entry-> node_name ||
5405- $ this ->state ->stack_of_open_elements ->contains_node ( $ last_entry )
5404+ $ last_entry instanceof AFE_Marker ||
5405+ $ this ->state ->stack_of_open_elements ->contains_node ( $ last_entry-> token )
54065406 ) {
54075407 return false ;
54085408 }
@@ -5433,8 +5433,8 @@ private function reconstruct_active_formatting_elements(): bool {
54335433 * > the stack of open elements, go to the step labeled rewind.
54345434 */
54355435 if (
5436- ' marker ' !== $ entry-> node_name &&
5437- ! $ this ->state ->stack_of_open_elements ->contains_node ( $ entry )
5436+ ! $ entry instanceof AFE_Marker &&
5437+ ! $ this ->state ->stack_of_open_elements ->contains_node ( $ entry-> token )
54385438 ) {
54395439 goto rewind;
54405440 }
@@ -5451,7 +5451,7 @@ private function reconstruct_active_formatting_elements(): bool {
54515451 * > element entry was created, to obtain new element.
54525452 */
54535453 create:
5454- $ this ->insert_html_element ( $ entry );
5454+ $ this ->insert_html_element ( $ entry-> token );
54555455
54565456 /*
54575457 * > 9. Replace the entry for entry in the list with an entry for new element.
@@ -5690,11 +5690,11 @@ private function run_adoption_agency_algorithm(): void {
56905690 */
56915691 $ formatting_element = null ;
56925692 foreach ( $ this ->state ->active_formatting_elements ->walk_up () as $ item ) {
5693- if ( ' marker ' === $ item-> node_name ) {
5693+ if ( $ item instanceof AFE_Marker ) {
56945694 break ;
56955695 }
56965696
5697- if ( $ subject === $ item ->node_name ) {
5697+ if ( $ subject === $ item ->tag_name ) {
56985698 $ formatting_element = $ item ;
56995699 break ;
57005700 }
@@ -5706,13 +5706,13 @@ private function run_adoption_agency_algorithm(): void {
57065706 }
57075707
57085708 // > If formatting element is not in the stack of open elements, then this is a parse error; remove the element from the list, and return.
5709- if ( ! $ this ->state ->stack_of_open_elements ->contains_node ( $ formatting_element ) ) {
5709+ if ( ! $ this ->state ->stack_of_open_elements ->contains_node ( $ formatting_element-> token ) ) {
57105710 $ this ->state ->active_formatting_elements ->remove_node ( $ formatting_element );
57115711 return ;
57125712 }
57135713
57145714 // > If formatting element is in the stack of open elements, but the element is not in scope, then this is a parse error; return.
5715- if ( ! $ this ->state ->stack_of_open_elements ->has_element_in_scope ( $ formatting_element ->node_name ) ) {
5715+ if ( ! $ this ->state ->stack_of_open_elements ->has_element_in_scope ( $ formatting_element ->tag_name ) ) {
57165716 return ;
57175717 }
57185718
@@ -5723,7 +5723,7 @@ private function run_adoption_agency_algorithm(): void {
57235723 $ is_above_formatting_element = true ;
57245724 $ furthest_block = null ;
57255725 foreach ( $ this ->state ->stack_of_open_elements ->walk_down () as $ item ) {
5726- if ( $ is_above_formatting_element && $ formatting_element ->bookmark_name !== $ item ->bookmark_name ) {
5726+ if ( $ is_above_formatting_element && $ formatting_element ->token -> bookmark_name !== $ item ->bookmark_name ) {
57275727 continue ;
57285728 }
57295729
@@ -5747,7 +5747,7 @@ private function run_adoption_agency_algorithm(): void {
57475747 foreach ( $ this ->state ->stack_of_open_elements ->walk_up () as $ item ) {
57485748 $ this ->state ->stack_of_open_elements ->pop ();
57495749
5750- if ( $ formatting_element ->bookmark_name === $ item ->bookmark_name ) {
5750+ if ( $ formatting_element ->token -> bookmark_name === $ item ->bookmark_name ) {
57515751 $ this ->state ->active_formatting_elements ->remove_node ( $ formatting_element );
57525752 return ;
57535753 }
@@ -6211,4 +6211,24 @@ protected static function get_encoding( string $label ): ?string {
62116211 * @access private
62126212 */
62136213 const CONSTRUCTOR_UNLOCK_CODE = 'Use WP_HTML_Processor::create_fragment() instead of calling the class constructor directly. ' ;
6214+
6215+ private function push_active_formatting_element ( WP_HTML_Token $ token ) {
6216+ $ bookmark = $ this ->bookmarks [ $ token ->bookmark_name ];
6217+ $ proc = new WP_HTML_Tag_Processor (
6218+ substr ( $ this ->html , $ bookmark ->start , $ bookmark ->length )
6219+ );
6220+ $ proc ->change_parsing_namespace ( $ token ->namespace );
6221+ $ proc ->next_tag ();
6222+ $ attributes = array ();
6223+ foreach ( $ proc ->get_attribute_names_with_prefix ( '' ) as $ name ) {
6224+ $ attributes [ $ name ] = $ proc ->get_attribute ( $ name );
6225+ }
6226+ $ afe = new AFE_Element (
6227+ $ token ->namespace ,
6228+ $ token ->node_name ,
6229+ $ attributes ,
6230+ $ token
6231+ );
6232+ $ this ->state ->active_formatting_elements ->push ( $ afe );
6233+ }
62146234}
0 commit comments