@@ -52,8 +52,10 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
52
52
}
53
53
}
54
54
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 ();
57
59
58
60
if ('block ' === $ componentName ) {
59
61
// 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
63
65
$ this ->currentComponents [\count ($ this ->currentComponents ) - 1 ]['hasDefaultBlock ' ] = false ;
64
66
}
65
67
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
+
66
77
$ output .= $ this ->consumeBlock ($ componentName );
67
78
68
79
continue ;
@@ -119,7 +130,7 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
119
130
continue ;
120
131
}
121
132
122
- $ char = $ this ->consumeChar () ;
133
+ $ char = $ this ->input [ $ this -> position ] ;
123
134
if ("\n" === $ char ) {
124
135
++$ this ->line ;
125
136
}
@@ -128,11 +139,13 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
128
139
if (!empty ($ this ->currentComponents )
129
140
&& !$ this ->currentComponents [\count ($ this ->currentComponents ) - 1 ]['hasDefaultBlock ' ]
130
141
&& preg_match ('/\S/ ' , $ char )
142
+ && !$ this ->check ('{% block ' )
131
143
) {
132
144
$ output .= $ this ->addDefaultBlock ();
133
145
}
134
146
135
147
$ output .= $ char ;
148
+ $ this ->consumeChar ();
136
149
}
137
150
138
151
if (!empty ($ this ->currentComponents )) {
@@ -374,10 +387,24 @@ private function consumeUntilEndBlock(): string
374
387
}
375
388
}
376
389
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
+
377
400
if ('<twig:block ' === substr ($ this ->input , $ this ->position , 11 )) {
378
401
++$ depth ;
379
402
}
380
403
404
+ if ('{% block ' === substr ($ this ->input , $ this ->position , 8 )) {
405
+ ++$ depth ;
406
+ }
407
+
381
408
if ("\n" === $ this ->input [$ this ->position ]) {
382
409
++$ this ->line ;
383
410
}
0 commit comments