@@ -497,20 +497,20 @@ public function get_raw_inner_markup() {
497497 return null ;
498498 }
499499
500- $ this ->set_bookmark ( 'start ' );
500+ $ this ->set_bookmark ( 'opener ' );
501501 $ found_tag = $ this ->step_until_tag_is_closed ();
502- $ this ->set_bookmark ( 'end ' );
502+ $ this ->set_bookmark ( 'closer ' );
503503
504504 if ( $ found_tag ) {
505- $ inner_markup = $ this ->substr_bookmarks ( 'after ' , 'start ' , 'before ' , 'end ' );
505+ $ inner_markup = $ this ->substr_bookmarks ( 'after ' , 'opener ' , 'before ' , 'closer ' );
506506 } else {
507507 // If there's no closing tag then the inner markup continues to the end of the document.
508- $ inner_markup = $ this ->substr_bookmark ( 'after ' , 'start ' );
508+ $ inner_markup = $ this ->substr_bookmark ( 'after ' , 'opener ' );
509509 }
510510
511- $ this ->seek ( 'start ' );
512- $ this ->release_bookmark ( 'start ' );
513- $ this ->release_bookmark ( 'end ' );
511+ $ this ->seek ( 'opener ' );
512+ $ this ->release_bookmark ( 'opener ' );
513+ $ this ->release_bookmark ( 'closer ' );
514514
515515 return $ inner_markup ;
516516 }
@@ -539,31 +539,75 @@ public function get_raw_outer_markup() {
539539 return null ;
540540 }
541541
542- $ this ->set_bookmark ( 'start ' );
542+ $ this ->set_bookmark ( 'opener ' );
543543 $ start_tag = $ this ->current_token ->node_name ;
544544 $ found_tag = $ this ->step_until_tag_is_closed ();
545- $ this ->set_bookmark ( 'end ' );
545+ $ this ->set_bookmark ( 'closer ' );
546546
547547 if ( $ found_tag ) {
548548 $ did_close = $ this ->get_tag () === $ start_tag && $ this ->is_tag_closer ();
549549 $ end_position = $ did_close ? 'after ' : 'before ' ;
550- $ outer_markup = $ this ->substr_bookmarks ( 'before ' , 'start ' , $ end_position , 'end ' );
550+ $ outer_markup = $ this ->substr_bookmarks ( 'before ' , 'opener ' , $ end_position , 'closer ' );
551551 } else {
552552 // If there's no closing tag then the outer markup continues to the end of the document.
553- $ outer_markup = $ this ->substr_bookmark ( 'before ' , 'start ' );
553+ $ outer_markup = $ this ->substr_bookmark ( 'before ' , 'opener ' );
554554 }
555555
556- $ this ->seek ( 'start ' );
557- $ this ->release_bookmark ( 'start ' );
558- $ this ->release_bookmark ( 'end ' );
556+ $ this ->seek ( 'opener ' );
557+ $ this ->release_bookmark ( 'opener ' );
558+ $ this ->release_bookmark ( 'closer ' );
559559
560560 return $ outer_markup ;
561561 }
562562
563+ /**
564+ * Replaces the raw HTML of the currently-matched tag's inner markup with new HTML.
565+ * This replaces the content between the tag opener and tag closer.
566+ *
567+ * @throws Exception When unable to set bookmark for internal tracking.
568+ *
569+ * @since 6.4.0
570+ *
571+ * @param string $new_html
572+ * @return bool|null Whether the contents were updated.
573+ */
574+ public function set_raw_inner_markup ( $ new_html ) {
575+ if ( null === $ this ->get_tag () ) {
576+ return null ;
577+ }
578+
579+ $ this ->set_bookmark ( 'opener ' );
580+ $ start_tag = $ this ->current_token ->node_name ;
581+
582+ if ( self ::is_void ( $ start_tag ) ) {
583+ $ this ->release_bookmark ( 'opener ' );
584+ return true ;
585+ }
586+
587+ $ found_tag = $ this ->step_until_tag_is_closed ();
588+ $ this ->set_bookmark ( 'closer ' );
589+
590+ if ( $ found_tag ) {
591+ $ this ->replace_using_bookmarks ( $ new_html , 'after ' , 'opener ' , 'before ' , 'closer ' );
592+ } else {
593+ // If there's no closing tag then the inner markup continues to the end of the document.
594+ $ this ->replace_using_bookmark ( $ new_html , 'after ' , 'opener ' );
595+ }
596+
597+ $ this ->seek ( 'opener ' );
598+ $ this ->release_bookmark ( 'opener ' );
599+ $ this ->release_bookmark ( 'closer ' );
600+ return true ;
601+ }
602+
563603 /**
564604 * Replaces the raw HTML of the currently-matched tag with new HTML.
565605 * This replaces the entire contents of the tag including the tag itself.
566606 *
607+ * @throws Exception When unable to set bookmark for internal tracking.
608+ *
609+ * @since 6.4.0
610+ *
567611 * @param string $new_html
568612 * @return bool|null Whether the contents were updated.
569613 */
@@ -572,30 +616,30 @@ public function set_raw_outer_markup( $new_html ) {
572616 return null ;
573617 }
574618
575- $ this ->set_bookmark ( 'start ' );
619+ $ this ->set_bookmark ( 'opener ' );
576620 $ start_tag = $ this ->current_token ->node_name ;
577621
578622 if ( self ::is_void ( $ start_tag ) ) {
579- $ this ->replace_using_bookmarks ( $ new_html , 'before ' , 'start ' , 'after ' , 'start ' );
580- $ this ->release_bookmark ( 'start ' );
623+ $ this ->replace_using_bookmarks ( $ new_html , 'before ' , 'opener ' , 'after ' , 'opener ' );
624+ $ this ->release_bookmark ( 'opener ' );
581625 return true ;
582626 }
583627
584628 $ found_tag = $ this ->step_until_tag_is_closed ();
585- $ this ->set_bookmark ( 'end ' );
629+ $ this ->set_bookmark ( 'closer ' );
586630
587631 if ( $ found_tag ) {
588632 $ did_close = $ this ->get_tag () === $ start_tag && $ this ->is_tag_closer ();
589633 $ end_position = $ did_close ? 'after ' : 'before ' ;
590- $ this ->replace_using_bookmarks ( $ new_html , 'before ' , 'start ' , $ end_position , 'end ' );
634+ $ this ->replace_using_bookmarks ( $ new_html , 'before ' , 'opener ' , $ end_position , 'closer ' );
591635 } else {
592636 // If there's no closing tag then the outer markup continues to the end of the document.
593- $ this ->replace_using_bookmark ( $ new_html , 'before ' , 'start ' );
637+ $ this ->replace_using_bookmark ( $ new_html , 'before ' , 'opener ' );
594638 }
595639
596- $ this ->seek ( 'start ' );
597- $ this ->release_bookmark ( 'start ' );
598- $ this ->release_bookmark ( 'end ' );
640+ $ this ->seek ( 'opener ' );
641+ $ this ->release_bookmark ( 'opener ' );
642+ $ this ->release_bookmark ( 'closer ' );
599643 return true ;
600644 }
601645
0 commit comments