@@ -158,14 +158,17 @@ private function parseLine(string $line): void
158158 $ unmatchedBlocks = 0 ;
159159 }
160160
161+ $ oldBlockLineStart = null ;
161162 if ($ blockStart ->isReplaceActiveBlockParser ()) {
162- $ this ->prepareActiveBlockParserForReplacement ();
163+ $ oldBlockLineStart = $ this ->prepareActiveBlockParserForReplacement ();
163164 }
164165
165166 foreach ($ blockStart ->getBlockParsers () as $ newBlockParser ) {
166- $ blockParser = $ this ->addChild ($ newBlockParser );
167+ $ blockParser = $ this ->addChild ($ newBlockParser, $ oldBlockLineStart );
167168 $ tryBlockStarts = $ newBlockParser ->isContainer ();
168169 }
170+
171+ unset($ oldBlockLineStart );
169172 }
170173
171174 // What remains at the offset is a text line. Add the text to the appropriate block.
@@ -275,12 +278,12 @@ private function processInlines(): void
275278 * Add block of type tag as a child of the tip. If the tip can't accept children, close and finalize it and try
276279 * its parent, and so on til we find a block that can accept children.
277280 */
278- private function addChild (BlockContinueParserInterface $ blockParser ): BlockContinueParserInterface
281+ private function addChild (BlockContinueParserInterface $ blockParser, ? int $ startLineNumber = null ): BlockContinueParserInterface
279282 {
280- $ blockParser ->getBlock ()->setStartLine ($ this ->lineNumber );
283+ $ blockParser ->getBlock ()->setStartLine ($ startLineNumber ?? $ this ->lineNumber );
281284
282285 while (! $ this ->getActiveBlockParser ()->canContain ($ blockParser ->getBlock ())) {
283- $ this ->closeBlockParsers (1 , $ this ->lineNumber - 1 );
286+ $ this ->closeBlockParsers (1 , ( $ startLineNumber ?? $ this ->lineNumber ) - 1 );
284287 }
285288
286289 $ this ->getActiveBlockParser ()->getBlock ()->appendChild ($ blockParser ->getBlock ());
@@ -307,7 +310,10 @@ private function deactivateBlockParser(): BlockContinueParserInterface
307310 return $ popped ;
308311 }
309312
310- private function prepareActiveBlockParserForReplacement (): void
313+ /**
314+ * @return int|null The line number where the old block started
315+ */
316+ private function prepareActiveBlockParserForReplacement (): ?int
311317 {
312318 // Note that we don't want to parse inlines or finalize this block, as it's getting replaced.
313319 $ old = $ this ->deactivateBlockParser ();
@@ -317,6 +323,8 @@ private function prepareActiveBlockParserForReplacement(): void
317323 }
318324
319325 $ old ->getBlock ()->detach ();
326+
327+ return $ old ->getBlock ()->getStartLine ();
320328 }
321329
322330 /**
0 commit comments