@@ -2391,6 +2391,89 @@ public function declarative_match( $pattern_html ) {
23912391 return true ;
23922392 }
23932393
2394+ /**
2395+ * @since 6.3.0
2396+ */
2397+ public function transform ( $ pattern_html , $ transformer_html ) {
2398+ $ visit_everything = array ( 'tag_closers ' => 'visit ' , 'funky_comments ' => 'visit ' );
2399+ $ pattern = new WP_HTML_Tag_Processor ( $ pattern_html );
2400+ $ transform = new WP_HTML_Tag_Processor ( $ transformer_html );
2401+
2402+ if (
2403+ ! $ pattern ->next_tag ( $ visit_everything ) ||
2404+ ! $ transform ->next_tag ( $ visit_everything ) ||
2405+ ! $ this ->declarative_match ( $ pattern_html )
2406+ ) {
2407+ return false ;
2408+ }
2409+
2410+ $ this ->set_bookmark ( 'match_start ' );
2411+
2412+ $ same_thing = function ( WP_HTML_Tag_Processor $ pattern , WP_HTML_Tag_Processor $ test ) {
2413+ if ( $ pattern ->is_funky_comment () ) {
2414+ // $this->placeholders++;
2415+ // $this->set_bookmark( "__placeholder_{$this->placeholders}" );
2416+ return true ;
2417+ }
2418+
2419+ if ( ! (
2420+ $ pattern ->get_tag () === $ test ->get_tag () &&
2421+ $ pattern ->is_tag_closer () === $ test ->is_tag_closer () &&
2422+ $ pattern ->is_funky_comment () === $ test ->is_funky_comment ()
2423+ ) ) {
2424+ return false ;
2425+ }
2426+
2427+ $ attribute_constraints = $ pattern ->get_attribute_names_with_prefix ( '' );
2428+ if ( null === $ attribute_constraints ) {
2429+ return true ;
2430+ }
2431+
2432+ foreach ( $ attribute_constraints as $ name ) {
2433+ if ( $ pattern ->get_attribute ( $ name ) !== $ test ->get_attribute ( $ name ) ) {
2434+ return false ;
2435+ }
2436+ }
2437+
2438+ return true ;
2439+ };
2440+
2441+ $ budget = 10 ;
2442+ while ( $ budget -- ) {
2443+ if ( $ same_thing ( $ pattern , $ transform ) ) {
2444+ if ( ! $ transform ->next_tag ( $ visit_everything ) ) {
2445+ goto drop_patterns;
2446+ }
2447+ $ this ->next_tag ( $ visit_everything );
2448+ $ pattern ->next_tag ( $ visit_everything );
2449+ continue ;
2450+ }
2451+
2452+ $ this ->set_bookmark ( 'here ' );
2453+ $ this ->lexical_updates [] = new WP_HTML_Text_Replacement (
2454+ $ this ->bookmarks ['here ' ]->start ,
2455+ $ this ->bookmarks ['here ' ]->end + 1 ,
2456+ ''
2457+ );
2458+ var_dump ( substr ( $ this ->html , $ this ->bookmarks ['here ' ]->start , $ this ->bookmarks ['here ' ]->end - $ this ->bookmarks ['here ' ]->start + 1 ) );
2459+ $ this ->get_updated_html ();
2460+ $ pattern ->next_tag ( $ visit_everything );
2461+ $ this ->next_tag ( $ visit_everything );
2462+ }
2463+
2464+ drop_patterns:
2465+ while ( $ pattern ->next_tag ( $ visit_everything ) ) {
2466+ $ this ->set_bookmark ( 'here ' );
2467+ $ this ->lexical_updates [] = new WP_HTML_Text_Replacement (
2468+ $ this ->bookmarks ['here ' ]->start ,
2469+ $ this ->bookmarks ['here ' ]->end + 1 ,
2470+ ''
2471+ );
2472+ var_dump ( substr ( $ this ->html , $ this ->bookmarks ['here ' ]->start , $ this ->bookmarks ['here ' ]->end - $ this ->bookmarks ['here ' ]->start + 1 ) );
2473+ $ this ->next_tag ( $ visit_everything );
2474+ }
2475+ }
2476+
23942477 /**
23952478 * Checks whether a given tag and its attributes match the search criteria.
23962479 *
0 commit comments