@@ -513,6 +513,11 @@ private function applyDedent(FragmentNode $fragment, Tag $startTag): void
513513 $ baseIndent = null ;
514514 $ atLineStart = true ;
515515 $ inlineChecked = false ;
516+ $ root = $ startTag ;
517+ while ($ root ->parent !== null ) {
518+ $ root = $ root ->parent ;
519+ }
520+ $ tagIndentLen = $ root ->position ->column - 1 ;
516521
517522 foreach ($ fragment ->children as $ i => $ child ) {
518523 if ($ child instanceof Nodes \TextNode && $ child ->content === '' ) {
@@ -545,12 +550,15 @@ private function applyDedent(FragmentNode $fragment, Tag $startTag): void
545550 if ($ hasContent ) {
546551 preg_match ('/^([ \t]+)/ ' , $ line , $ m );
547552 $ baseIndent = $ m [1 ] ?? null ;
548- if ($ baseIndent === null ) {
549- return ; // first content line has no indent
553+ if ($ baseIndent === null || strlen ( $ baseIndent ) <= $ tagIndentLen ) {
554+ return ; // first content line has no indent beyond tag level
550555 }
551556
552557 } elseif ($ continuesWithExpr ) {
553558 $ baseIndent = $ line ;
559+ if (strlen ($ baseIndent ) <= $ tagIndentLen ) {
560+ return ;
561+ }
554562
555563 } else {
556564 continue ; // blank line before detection
@@ -564,7 +572,7 @@ private function applyDedent(FragmentNode $fragment, Tag $startTag): void
564572 continue ; // blank line, strip silently
565573 }
566574
567- $ line = substr ($ line , strlen ((string ) $ baseIndent ));
575+ $ line = substr ($ line , 0 , $ tagIndentLen ) . substr ( $ line , strlen ((string ) $ baseIndent ));
568576 }
569577
570578 unset($ line );
0 commit comments