@@ -158,12 +158,13 @@ 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
}
169
170
}
@@ -275,12 +276,12 @@ private function processInlines(): void
275
276
* 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
277
* its parent, and so on til we find a block that can accept children.
277
278
*/
278
- private function addChild (BlockContinueParserInterface $ blockParser ): BlockContinueParserInterface
279
+ private function addChild (BlockContinueParserInterface $ blockParser, ? int $ startLineNumber = null ): BlockContinueParserInterface
279
280
{
280
- $ blockParser ->getBlock ()->setStartLine ($ this ->lineNumber );
281
+ $ blockParser ->getBlock ()->setStartLine ($ startLineNumber ?? $ this ->lineNumber );
281
282
282
283
while (! $ this ->getActiveBlockParser ()->canContain ($ blockParser ->getBlock ())) {
283
- $ this ->closeBlockParsers (1 , $ this ->lineNumber - 1 );
284
+ $ this ->closeBlockParsers (1 , ( $ startLineNumber ?? $ this ->lineNumber ) - 1 );
284
285
}
285
286
286
287
$ this ->getActiveBlockParser ()->getBlock ()->appendChild ($ blockParser ->getBlock ());
@@ -307,7 +308,10 @@ private function deactivateBlockParser(): BlockContinueParserInterface
307
308
return $ popped ;
308
309
}
309
310
310
- private function prepareActiveBlockParserForReplacement (): void
311
+ /**
312
+ * @return int|null The line number where the old block started
313
+ */
314
+ private function prepareActiveBlockParserForReplacement (): ?int
311
315
{
312
316
// Note that we don't want to parse inlines or finalize this block, as it's getting replaced.
313
317
$ old = $ this ->deactivateBlockParser ();
@@ -317,6 +321,8 @@ private function prepareActiveBlockParserForReplacement(): void
317
321
}
318
322
319
323
$ old ->getBlock ()->detach ();
324
+
325
+ return $ old ->getBlock ()->getStartLine ();
320
326
}
321
327
322
328
/**
0 commit comments