@@ -158,12 +158,13 @@ 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 }
169170 }
@@ -275,12 +276,12 @@ private function processInlines(): void
275276 * Add block of type tag as a child of the tip. If the tip can't accept children, close and finalize it and try
276277 * its parent, and so on til we find a block that can accept children.
277278 */
278- private function addChild (BlockContinueParserInterface $ blockParser ): BlockContinueParserInterface
279+ private function addChild (BlockContinueParserInterface $ blockParser, ? int $ startLineNumber = null ): BlockContinueParserInterface
279280 {
280- $ blockParser ->getBlock ()->setStartLine ($ this ->lineNumber );
281+ $ blockParser ->getBlock ()->setStartLine ($ startLineNumber ?? $ this ->lineNumber );
281282
282283 while (! $ this ->getActiveBlockParser ()->canContain ($ blockParser ->getBlock ())) {
283- $ this ->closeBlockParsers (1 , $ this ->lineNumber - 1 );
284+ $ this ->closeBlockParsers (1 , ( $ startLineNumber ?? $ this ->lineNumber ) - 1 );
284285 }
285286
286287 $ this ->getActiveBlockParser ()->getBlock ()->appendChild ($ blockParser ->getBlock ());
@@ -307,7 +308,10 @@ private function deactivateBlockParser(): BlockContinueParserInterface
307308 return $ popped ;
308309 }
309310
310- private function prepareActiveBlockParserForReplacement (): void
311+ /**
312+ * @return int|null The line number where the old block started
313+ */
314+ private function prepareActiveBlockParserForReplacement (): ?int
311315 {
312316 // Note that we don't want to parse inlines or finalize this block, as it's getting replaced.
313317 $ old = $ this ->deactivateBlockParser ();
@@ -317,6 +321,8 @@ private function prepareActiveBlockParserForReplacement(): void
317321 }
318322
319323 $ old ->getBlock ()->detach ();
324+
325+ return $ old ->getBlock ()->getStartLine ();
320326 }
321327
322328 /**
0 commit comments