@@ -52,8 +52,10 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
5252 }
5353 }
5454
55- if ($ this ->consume ('<twig: ' )) {
56- $ componentName = $ this ->consumeComponentName ();
55+ $ isTwigHtmlOpening = $ this ->consume ('<twig: ' );
56+ $ isTraditionalBlockOpening = false ;
57+ if ($ isTwigHtmlOpening || (0 !== \count ($ this ->currentComponents ) && $ isTraditionalBlockOpening = $ this ->consume ('{% block ' ))) {
58+ $ componentName = $ isTraditionalBlockOpening ? 'block ' : $ this ->consumeComponentName ();
5759
5860 if ('block ' === $ componentName ) {
5961 // if we're already inside the "default" block, let's close it
@@ -63,6 +65,15 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
6365 $ this ->currentComponents [\count ($ this ->currentComponents ) - 1 ]['hasDefaultBlock ' ] = false ;
6466 }
6567
68+ if ($ isTraditionalBlockOpening ) {
69+ // add what we've consumed so far
70+ $ output .= '{% block ' ;
71+ $ output .= $ this ->consumeUntil ('%} ' );
72+ $ output .= $ this ->consumeUntilEndBlock ();
73+
74+ continue ;
75+ }
76+
6677 $ output .= $ this ->consumeBlock ($ componentName );
6778
6879 continue ;
@@ -119,7 +130,7 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
119130 continue ;
120131 }
121132
122- $ char = $ this ->consumeChar () ;
133+ $ char = $ this ->input [ $ this -> position ] ;
123134 if ("\n" === $ char ) {
124135 ++$ this ->line ;
125136 }
@@ -128,11 +139,13 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
128139 if (!empty ($ this ->currentComponents )
129140 && !$ this ->currentComponents [\count ($ this ->currentComponents ) - 1 ]['hasDefaultBlock ' ]
130141 && preg_match ('/\S/ ' , $ char )
142+ && !$ this ->check ('{% block ' )
131143 ) {
132144 $ output .= $ this ->addDefaultBlock ();
133145 }
134146
135147 $ output .= $ char ;
148+ $ this ->consumeChar ();
136149 }
137150
138151 if (!empty ($ this ->currentComponents )) {
@@ -374,10 +387,24 @@ private function consumeUntilEndBlock(): string
374387 }
375388 }
376389
390+ if ('{% endblock %} ' === substr ($ this ->input , $ this ->position , 14 )) {
391+ if (1 === $ depth ) {
392+ // in this case, we want to advanced ALL the way beyond the endblock
393+ $ this ->position += 14 ;
394+ break ;
395+ } else {
396+ --$ depth ;
397+ }
398+ }
399+
377400 if ('<twig:block ' === substr ($ this ->input , $ this ->position , 11 )) {
378401 ++$ depth ;
379402 }
380403
404+ if ('{% block ' === substr ($ this ->input , $ this ->position , 8 )) {
405+ ++$ depth ;
406+ }
407+
381408 if ("\n" === $ this ->input [$ this ->position ]) {
382409 ++$ this ->line ;
383410 }
0 commit comments