Skip to content

Commit

Permalink
Only remember parsers that might contain inlines
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Jul 3, 2021
1 parent a490ca5 commit 5c01d73
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Parser/MarkdownParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class MarkdownParser implements MarkdownParserInterface
private array $activeBlockParsers = [];

/**
* @var array<int, BlockContinueParserInterface>
* @var array<int, BlockContinueParserWithInlinesInterface>
*
* @psalm-readonly-allow-private-mutation
*/
Expand Down Expand Up @@ -240,8 +240,12 @@ private function closeBlockParsers(int $count, int $endLineNumber): void
for ($i = 0; $i < $count; $i++) {
$blockParser = $this->deactivateBlockParser();
$this->finalize($blockParser, $endLineNumber);
// Remember for inline parsing
$this->closedBlockParsers[] = $blockParser;

// phpcs:disable SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed
if ($blockParser instanceof BlockContinueParserWithInlinesInterface) {
// Remember for inline parsing
$this->closedBlockParsers[] = $blockParser;
}
}
}

Expand All @@ -268,9 +272,7 @@ private function processInlines(): void
$p = new InlineParserEngine($this->environment, $this->referenceMap);

foreach ($this->closedBlockParsers as $blockParser) {
if ($blockParser instanceof BlockContinueParserWithInlinesInterface) {
$blockParser->parseInlines($p);
}
$blockParser->parseInlines($p);
}
}

Expand Down

0 comments on commit 5c01d73

Please sign in to comment.