@@ -158,14 +158,17 @@ private function parseLine(string $line): void
158
158
$ unmatchedBlocks = 0 ;
159
159
}
160
160
161
+ $ oldBlockLineStart = null ;
161
162
if ($ blockStart ->isReplaceActiveBlockParser ()) {
162
- $ this ->prepareActiveBlockParserForReplacement ();
163
+ $ oldBlockLineStart = $ this ->prepareActiveBlockParserForReplacement ();
163
164
}
164
165
165
166
foreach ($ blockStart ->getBlockParsers () as $ newBlockParser ) {
166
- $ blockParser = $ this ->addChild ($ newBlockParser );
167
+ $ blockParser = $ this ->addChild ($ newBlockParser, $ oldBlockLineStart );
167
168
$ tryBlockStarts = $ newBlockParser ->isContainer ();
168
169
}
170
+
171
+ unset($ oldBlockLineStart );
169
172
}
170
173
171
174
// What remains at the offset is a text line. Add the text to the appropriate block.
@@ -275,12 +278,12 @@ private function processInlines(): void
275
278
* Add block of type tag as a child of the tip. If the tip can't accept children, close and finalize it and try
276
279
* its parent, and so on til we find a block that can accept children.
277
280
*/
278
- private function addChild (BlockContinueParserInterface $ blockParser ): BlockContinueParserInterface
281
+ private function addChild (BlockContinueParserInterface $ blockParser, ? int $ startLineNumber = null ): BlockContinueParserInterface
279
282
{
280
- $ blockParser ->getBlock ()->setStartLine ($ this ->lineNumber );
283
+ $ blockParser ->getBlock ()->setStartLine ($ startLineNumber ?? $ this ->lineNumber );
281
284
282
285
while (! $ this ->getActiveBlockParser ()->canContain ($ blockParser ->getBlock ())) {
283
- $ this ->closeBlockParsers (1 , $ this ->lineNumber - 1 );
286
+ $ this ->closeBlockParsers (1 , ( $ startLineNumber ?? $ this ->lineNumber ) - 1 );
284
287
}
285
288
286
289
$ this ->getActiveBlockParser ()->getBlock ()->appendChild ($ blockParser ->getBlock ());
@@ -307,7 +310,10 @@ private function deactivateBlockParser(): BlockContinueParserInterface
307
310
return $ popped ;
308
311
}
309
312
310
- private function prepareActiveBlockParserForReplacement (): void
313
+ /**
314
+ * @return int|null The line number where the old block started
315
+ */
316
+ private function prepareActiveBlockParserForReplacement (): ?int
311
317
{
312
318
// Note that we don't want to parse inlines or finalize this block, as it's getting replaced.
313
319
$ old = $ this ->deactivateBlockParser ();
@@ -317,6 +323,8 @@ private function prepareActiveBlockParserForReplacement(): void
317
323
}
318
324
319
325
$ old ->getBlock ()->detach ();
326
+
327
+ return $ old ->getBlock ()->getStartLine ();
320
328
}
321
329
322
330
/**
0 commit comments