From 5e85a0c983a48172153cfe6cf2030cf1266184f6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Dec 2024 21:10:13 +0100 Subject: [PATCH] Slimmer formatting for single line annotations --- .../Actions/GeneratesTableOfContents.php | 36 +++++-------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/packages/framework/src/Framework/Actions/GeneratesTableOfContents.php b/packages/framework/src/Framework/Actions/GeneratesTableOfContents.php index ca06d36a3a0..292ae238840 100644 --- a/packages/framework/src/Framework/Actions/GeneratesTableOfContents.php +++ b/packages/framework/src/Framework/Actions/GeneratesTableOfContents.php @@ -26,17 +26,13 @@ public function __construct(Markdown|string $markdown) $this->maxHeadingLevel = Config::getInt('docs.sidebar.table_of_contents.max_heading_level', 4); } - /** - * @return array - */ + /** @return array */ public function execute(): array { return $this->buildTableOfContents($this->parseHeadings()); } - /** - * @return array - */ + /** @return array */ protected function parseHeadings(): array { $matches = $this->matchHeadingPatterns(); @@ -55,9 +51,7 @@ protected function parseHeadings(): array return $headings; } - /** - * @return array{0: array, 1: array, 2: array, 3: array} - */ + /** @return array{0: array, 1: array, 2: array, 3: array} */ protected function matchHeadingPatterns(): array { // Match both ATX-style (###) and Setext-style (===, ---) headers @@ -80,9 +74,7 @@ protected function parseHeadingData(string $heading, array $matches, int $index) return $this->parseSetextHeading($matches[2][$index], $matches[3][$index]); } - /** - * @return array{level: int, title: string} - */ + /** @return array{level: int, title: string} */ protected function parseAtxHeading(string $heading, string $title): array { return [ @@ -91,9 +83,7 @@ protected function parseAtxHeading(string $heading, string $title): array ]; } - /** - * @return array{level: int, title: string}|null - */ + /** @return array{level: int, title: string}|null */ protected function parseSetextHeading(string $title, string $marker): ?array { $level = $marker === '=' ? 1 : 2; @@ -144,9 +134,7 @@ protected function buildTableOfContents(array $headings): array return $items; } - /** - * @param array{level: int, title: string, identifier: string} $heading - */ + /** @param array{level: int, title: string, identifier: string} $heading */ protected function isHeadingWithinBounds(array $heading): bool { return $heading['level'] >= $this->minHeadingLevel && @@ -166,9 +154,7 @@ protected function createTableItem(array $heading): array ]; } - /** - * @param array> $stack - */ + /** @param array> $stack */ protected function updateStackForHeadingLevel(array &$stack, int $currentLevel, int $previousLevel): void { if ($currentLevel > $previousLevel) { @@ -180,9 +166,7 @@ protected function updateStackForHeadingLevel(array &$stack, int $currentLevel, } } - /** - * @param array> $stack - */ + /** @param array> $stack */ protected function nestNewLevel(array &$stack): void { $lastStackIndex = count($stack) - 1; @@ -191,9 +175,7 @@ protected function nestNewLevel(array &$stack): void $stack[] = &$stack[$lastStackIndex][$lastItemIndex]['children']; } - /** - * @param array> $stack - */ + /** @param array> $stack */ protected function unwindStack(array &$stack, int $currentLevel): void { array_splice($stack, $currentLevel - $this->minHeadingLevel + 1);