@@ -442,20 +442,20 @@ public function get_raw_inner_markup() {
442442 return null ;
443443 }
444444
445- $ this ->set_bookmark ( 'start ' );
445+ $ this ->set_bookmark ( 'opener ' );
446446 $ found_tag = $ this ->step_until_tag_is_closed ();
447- $ this ->set_bookmark ( 'end ' );
447+ $ this ->set_bookmark ( 'closer ' );
448448
449449 if ( $ found_tag ) {
450- $ inner_markup = $ this ->substr_bookmarks ( 'after ' , 'start ' , 'before ' , 'end ' );
450+ $ inner_markup = $ this ->substr_bookmarks ( 'after ' , 'opener ' , 'before ' , 'closer ' );
451451 } else {
452452 // If there's no closing tag then the inner markup continues to the end of the document.
453- $ inner_markup = $ this ->substr_bookmark ( 'after ' , 'start ' );
453+ $ inner_markup = $ this ->substr_bookmark ( 'after ' , 'opener ' );
454454 }
455455
456- $ this ->seek ( 'start ' );
457- $ this ->release_bookmark ( 'start ' );
458- $ this ->release_bookmark ( 'end ' );
456+ $ this ->seek ( 'opener ' );
457+ $ this ->release_bookmark ( 'opener ' );
458+ $ this ->release_bookmark ( 'closer ' );
459459
460460 return $ inner_markup ;
461461 }
@@ -484,31 +484,75 @@ public function get_raw_outer_markup() {
484484 return null ;
485485 }
486486
487- $ this ->set_bookmark ( 'start ' );
487+ $ this ->set_bookmark ( 'opener ' );
488488 $ start_tag = $ this ->current_token ->node_name ;
489489 $ found_tag = $ this ->step_until_tag_is_closed ();
490- $ this ->set_bookmark ( 'end ' );
490+ $ this ->set_bookmark ( 'closer ' );
491491
492492 if ( $ found_tag ) {
493493 $ did_close = $ this ->get_tag () === $ start_tag && $ this ->is_tag_closer ();
494494 $ end_position = $ did_close ? 'after ' : 'before ' ;
495- $ outer_markup = $ this ->substr_bookmarks ( 'before ' , 'start ' , $ end_position , 'end ' );
495+ $ outer_markup = $ this ->substr_bookmarks ( 'before ' , 'opener ' , $ end_position , 'closer ' );
496496 } else {
497497 // If there's no closing tag then the outer markup continues to the end of the document.
498- $ outer_markup = $ this ->substr_bookmark ( 'before ' , 'start ' );
498+ $ outer_markup = $ this ->substr_bookmark ( 'before ' , 'opener ' );
499499 }
500500
501- $ this ->seek ( 'start ' );
502- $ this ->release_bookmark ( 'start ' );
503- $ this ->release_bookmark ( 'end ' );
501+ $ this ->seek ( 'opener ' );
502+ $ this ->release_bookmark ( 'opener ' );
503+ $ this ->release_bookmark ( 'closer ' );
504504
505505 return $ outer_markup ;
506506 }
507507
508+ /**
509+ * Replaces the raw HTML of the currently-matched tag's inner markup with new HTML.
510+ * This replaces the content between the tag opener and tag closer.
511+ *
512+ * @throws Exception When unable to set bookmark for internal tracking.
513+ *
514+ * @since 6.4.0
515+ *
516+ * @param string $new_html
517+ * @return bool|null Whether the contents were updated.
518+ */
519+ public function set_raw_inner_markup ( $ new_html ) {
520+ if ( null === $ this ->get_tag () ) {
521+ return null ;
522+ }
523+
524+ $ this ->set_bookmark ( 'opener ' );
525+ $ start_tag = $ this ->current_token ->node_name ;
526+
527+ if ( self ::is_void ( $ start_tag ) ) {
528+ $ this ->release_bookmark ( 'opener ' );
529+ return true ;
530+ }
531+
532+ $ found_tag = $ this ->step_until_tag_is_closed ();
533+ $ this ->set_bookmark ( 'closer ' );
534+
535+ if ( $ found_tag ) {
536+ $ this ->replace_using_bookmarks ( $ new_html , 'after ' , 'opener ' , 'before ' , 'closer ' );
537+ } else {
538+ // If there's no closing tag then the inner markup continues to the end of the document.
539+ $ this ->replace_using_bookmark ( $ new_html , 'after ' , 'opener ' );
540+ }
541+
542+ $ this ->seek ( 'opener ' );
543+ $ this ->release_bookmark ( 'opener ' );
544+ $ this ->release_bookmark ( 'closer ' );
545+ return true ;
546+ }
547+
508548 /**
509549 * Replaces the raw HTML of the currently-matched tag with new HTML.
510550 * This replaces the entire contents of the tag including the tag itself.
511551 *
552+ * @throws Exception When unable to set bookmark for internal tracking.
553+ *
554+ * @since 6.4.0
555+ *
512556 * @param string $new_html
513557 * @return bool|null Whether the contents were updated.
514558 */
@@ -517,30 +561,30 @@ public function set_raw_outer_markup( $new_html ) {
517561 return null ;
518562 }
519563
520- $ this ->set_bookmark ( 'start ' );
564+ $ this ->set_bookmark ( 'opener ' );
521565 $ start_tag = $ this ->current_token ->node_name ;
522566
523567 if ( self ::is_void ( $ start_tag ) ) {
524- $ this ->replace_using_bookmarks ( $ new_html , 'before ' , 'start ' , 'after ' , 'start ' );
525- $ this ->release_bookmark ( 'start ' );
568+ $ this ->replace_using_bookmarks ( $ new_html , 'before ' , 'opener ' , 'after ' , 'opener ' );
569+ $ this ->release_bookmark ( 'opener ' );
526570 return true ;
527571 }
528572
529573 $ found_tag = $ this ->step_until_tag_is_closed ();
530- $ this ->set_bookmark ( 'end ' );
574+ $ this ->set_bookmark ( 'closer ' );
531575
532576 if ( $ found_tag ) {
533577 $ did_close = $ this ->get_tag () === $ start_tag && $ this ->is_tag_closer ();
534578 $ end_position = $ did_close ? 'after ' : 'before ' ;
535- $ this ->replace_using_bookmarks ( $ new_html , 'before ' , 'start ' , $ end_position , 'end ' );
579+ $ this ->replace_using_bookmarks ( $ new_html , 'before ' , 'opener ' , $ end_position , 'closer ' );
536580 } else {
537581 // If there's no closing tag then the outer markup continues to the end of the document.
538- $ this ->replace_using_bookmark ( $ new_html , 'before ' , 'start ' );
582+ $ this ->replace_using_bookmark ( $ new_html , 'before ' , 'opener ' );
539583 }
540584
541- $ this ->seek ( 'start ' );
542- $ this ->release_bookmark ( 'start ' );
543- $ this ->release_bookmark ( 'end ' );
585+ $ this ->seek ( 'opener ' );
586+ $ this ->release_bookmark ( 'opener ' );
587+ $ this ->release_bookmark ( 'closer ' );
544588 return true ;
545589 }
546590
0 commit comments