diff --git a/app/Http/Controllers/ShowDocumentationController.php b/app/Http/Controllers/ShowDocumentationController.php index bdcc697a..8dda7bb3 100644 --- a/app/Http/Controllers/ShowDocumentationController.php +++ b/app/Http/Controllers/ShowDocumentationController.php @@ -104,7 +104,7 @@ protected function getPageProperties($platform, $version, $page = null): array $pageProperties['content'] = CommonMark::convertToHtml($document->body(), [ 'user' => auth()->user(), ]); - $pageProperties['tableOfContents'] = $this->extractTableOfContents($document->body()); + $pageProperties['tableOfContents'] = $this->extractTableOfContents($pageProperties['content']); $navigation = $this->getNavigation($platform, $version); $pageProperties['navigation'] = Menu::build($navigation, function (Menu $menu, $nav): void { @@ -386,21 +386,18 @@ protected function flattenNavigationPages(array $navigation): array return $pages; } - protected function extractTableOfContents(string $document): array + protected function extractTableOfContents(string $html): array { - // Remove code blocks which might contain headers. - $document = preg_replace('/```[a-z]*\s(.*?)```/s', '', $document); + if (! preg_match_all('/<(h[23])\s+id="([^"]+)"[^>]*>(.*?)<\/\1>/si', $html, $matches, PREG_SET_ORDER)) { + return []; + } - return collect(explode(PHP_EOL, $document)) - ->reject(function (string $line) { - // Only search for level 2 and 3 headings. - return ! Str::startsWith($line, '## ') && ! Str::startsWith($line, '### '); - }) - ->map(function (string $line) { + return collect($matches) + ->map(function (array $match) { return [ - 'level' => strlen(trim(Str::before($line, '# '))) + 1, - 'title' => $title = htmlspecialchars_decode(trim(Str::after($line, '# '))), - 'anchor' => Str::slug(Str::replace('`', 'code', $title)), + 'level' => (int) $match[1][1], + 'title' => html_entity_decode(trim(strip_tags(preg_replace('/]*>.*?<\/a>/i', '', $match[3]))), ENT_QUOTES | ENT_HTML5), + 'anchor' => $match[2], ]; }) ->values() diff --git a/resources/css/app.css b/resources/css/app.css index 601e0ffa..b87db60d 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -79,9 +79,9 @@ } } -/* Prevents scrollbars from appearing when a popover is open */ -html:has(#mobile-menu-popover:popover-open) { - overflow: hidden; +/* Compensate for custom scrollbar width when Flux locks scroll */ +html[data-flux-scroll-unlock] { + padding-right: 8px !important; } /* Scrollbar width */ diff --git a/resources/views/components/docs/toc-and-sponsors.blade.php b/resources/views/components/docs/toc-and-sponsors.blade.php index a20a78ca..528919a5 100644 --- a/resources/views/components/docs/toc-and-sponsors.blade.php +++ b/resources/views/components/docs/toc-and-sponsors.blade.php @@ -1,35 +1,6 @@ {{-- Copy as Markdown Button --}} -{{-- On this page --}} -

- {{-- Icon --}} - - - {{-- Label --}} -
On this page
-

- -{{-- Table of contents --}} -@if (count($tableOfContents) > 0) - -@endif -
diff --git a/resources/views/components/plugin-toc.blade.php b/resources/views/components/plugin-toc.blade.php index ad14bdf3..f4803e5a 100644 --- a/resources/views/components/plugin-toc.blade.php +++ b/resources/views/components/plugin-toc.blade.php @@ -15,21 +15,25 @@ }" x-show="headings.length > 0" x-cloak - class="mb-6" > -

- -
On this page
-

+ + + + On this page + -
- -
+ + + +
diff --git a/resources/views/docs/index.blade.php b/resources/views/docs/index.blade.php index 71d16f22..a1034f1b 100644 --- a/resources/views/docs/index.blade.php +++ b/resources/views/docs/index.blade.php @@ -53,37 +53,41 @@ {{-- Copy as Markdown Button --}} -
-

- {{-- Icon --}} - - {{-- Label --}} -
On this page
-

- @if (count($tableOfContents) > 0) - - @endif -
- + @if (count($tableOfContents) > 0) +
+
+ + + + On this page + + + + + + +
+
+ @endif +
{!! $content !!}
diff --git a/resources/views/plugin-show.blade.php b/resources/views/plugin-show.blade.php index 8bfd2888..f76a8f3f 100644 --- a/resources/views/plugin-show.blade.php +++ b/resources/views/plugin-show.blade.php @@ -95,38 +95,42 @@ class="font-mono text-2xl font-bold sm:text-3xl"
- {{-- Main content - README --}} -
- @if ($plugin->readme_html) - - @endif - -
+ {{-- Main content - README --}} +
@if ($plugin->readme_html) - {!! $plugin->readme_html !!} - @else -
-

- README not available yet. -

-
+
+
+ +
+
@endif -
-
+ +
+ @if ($plugin->readme_html) + {!! $plugin->readme_html !!} + @else +
+

+ README not available yet. +

+
+ @endif +
+
{{-- Sidebar - Plugin details --}}