Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/Parser/MarkdownParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ final class MarkdownParser implements MarkdownParserInterface
/** @psalm-readonly-allow-private-mutation */
private Cursor $cursor;

/** @psalm-readonly-allow-private-mutation */
private BlockContinueParserInterface $activeBlockParser;

/**
* @var array<int, BlockContinueParserInterface>
*
Expand Down Expand Up @@ -297,6 +300,7 @@ private function addChild(BlockContinueParserInterface $blockParser, ?int $start
private function activateBlockParser(BlockContinueParserInterface $blockParser): void
{
$this->activeBlockParsers[] = $blockParser;
$this->activeBlockParser = $blockParser;
}

/**
Expand All @@ -309,6 +313,11 @@ private function deactivateBlockParser(): BlockContinueParserInterface
throw new ParserLogicException('The last block parser should not be deactivated');
}

$last = \end($this->activeBlockParsers);
if ($last !== false) {
$this->activeBlockParser = $last;
}

return $popped;
}

Expand Down Expand Up @@ -346,11 +355,6 @@ private function updateReferenceMap(iterable $references): void
*/
public function getActiveBlockParser(): BlockContinueParserInterface
{
$active = \end($this->activeBlockParsers);
if ($active === false) {
throw new ParserLogicException('No active block parsers are available');
}

return $active;
return $this->activeBlockParser;
}
}
7 changes: 6 additions & 1 deletion src/Util/RegexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ public static function isLetter(?string $character): bool
return false;
}

return \preg_match('/[\pL]/u', $character) === 1;
// Fast path for ASCII (the common case in Markdown); ctype_alpha is locale-independent for single bytes
if (\strlen($character) === 1) {
return \ctype_alpha($character);
}

return \preg_match('/^\pL/u', $character) === 1;
}

/**
Expand Down