Skip to content

Commit

Permalink
Slimmer formatting for single line annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 8, 2024
1 parent b195b2f commit 17fa356
Showing 1 changed file with 9 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, array{title: string, identifier: string, children: array}>
*/
/** @return array<int, array{title: string, identifier: string, children: array}> */
public function execute(): array
{
return $this->buildTableOfContents($this->parseHeadings());
}

/**
* @return array<int, array{level: int, title: string, identifier: string}>
*/
/** @return array<int, array{level: int, title: string, identifier: string}> */
protected function parseHeadings(): array
{
$matches = $this->matchHeadingPatterns();
Expand All @@ -55,9 +51,7 @@ protected function parseHeadings(): array
return $headings;
}

/**
* @return array{0: array<int, string>, 1: array<int, string>, 2: array<int, string>, 3: array<int, string>}
*/
/** @return array{0: array<int, string>, 1: array<int, string>, 2: array<int, string>, 3: array<int, string>} */
protected function matchHeadingPatterns(): array
{
// Match both ATX-style (###) and Setext-style (===, ---) headers
Expand All @@ -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 [
Expand All @@ -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;
Expand Down Expand Up @@ -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 &&
Expand All @@ -166,9 +154,7 @@ protected function createTableItem(array $heading): array
];
}

/**
* @param array<int, array<int, array{title: string, identifier: string, children: array}>> $stack
*/
/** @param array<int, array<int, array{title: string, identifier: string, children: array}>> $stack */
protected function updateStackForHeadingLevel(array &$stack, int $currentLevel, int $previousLevel): void
{
if ($currentLevel > $previousLevel) {
Expand All @@ -180,9 +166,7 @@ protected function updateStackForHeadingLevel(array &$stack, int $currentLevel,
}
}

/**
* @param array<int, array<int, array{title: string, identifier: string, children: array}>> $stack
*/
/** @param array<int, array<int, array{title: string, identifier: string, children: array}>> $stack */
protected function nestNewLevel(array &$stack): void
{
$lastStackIndex = count($stack) - 1;
Expand All @@ -191,9 +175,7 @@ protected function nestNewLevel(array &$stack): void
$stack[] = &$stack[$lastStackIndex][$lastItemIndex]['children'];
}

/**
* @param array<int, array<int, array{title: string, identifier: string, children: array}>> $stack
*/
/** @param array<int, array<int, array{title: string, identifier: string, children: array}>> $stack */
protected function unwindStack(array &$stack, int $currentLevel): void
{
array_splice($stack, $currentLevel - $this->minHeadingLevel + 1);
Expand Down

0 comments on commit 17fa356

Please sign in to comment.