Skip to content

Commit 139cd60

Browse files
saundefinedtabuna
andauthored
Add Laravel 11.x Docs (#110)
* Add Laravel 11.x Docs * Add Doc tab support Should fix #102 * Update reset.scss * Update composer.lock --------- Co-authored-by: Alexandr Chernyaev <[email protected]>
1 parent 59afeec commit 139cd60

File tree

6 files changed

+445
-215
lines changed

6 files changed

+445
-215
lines changed

app/Docs.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App;
44

5+
use App\Markdown\GithubFlavoredMarkdownConverter;
56
use App\Models\Document;
67
use App\Models\DocumentationSection;
78
use Exception;
@@ -19,7 +20,7 @@ class Docs
1920
/**
2021
* Default version of Laravel documentation
2122
*/
22-
public const DEFAULT_VERSION = '10.x';
23+
public const DEFAULT_VERSION = '11.x';
2324

2425
/**
2526
* Array of supported versions
@@ -115,11 +116,11 @@ public function variables(?string $key = null): mixed
115116
public function content(): ?string
116117
{
117118
return once(function () {
118-
return Str::of($this->raw())
119+
return (new GithubFlavoredMarkdownConverter())->convert(Str::of($this->raw())
119120
->replace('{{version}}', $this->version)
120121
->after('---')
121122
->after('---')
122-
->markdown();
123+
);
123124
});
124125
}
125126

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Markdown;
4+
5+
use Laravel\Unfenced\UnfencedExtension;
6+
use League\CommonMark\Environment\Environment;
7+
use League\CommonMark\Environment\EnvironmentInterface;
8+
use League\CommonMark\Extension\Attributes\AttributesExtension;
9+
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
10+
use League\CommonMark\MarkdownConverter;
11+
12+
/**
13+
* Converts GitHub Flavored Markdown to HTML.
14+
*/
15+
class GithubFlavoredMarkdownConverter extends MarkdownConverter
16+
{
17+
/**
18+
* Create a new Markdown converter pre-configured for GFM
19+
*
20+
* @param array<string, mixed> $config
21+
*/
22+
public function __construct(array $config = [])
23+
{
24+
$environment = new Environment($config);
25+
$environment->addExtension(new CommonMarkCoreExtension());
26+
$environment->addExtension(new GithubFlavoredMarkdownExtension());
27+
$environment->addExtension(new UnfencedExtension());
28+
$environment->addExtension(new AttributesExtension());
29+
30+
parent::__construct($environment);
31+
}
32+
33+
public function getEnvironment(): EnvironmentInterface
34+
{
35+
\assert($this->environment instanceof EnvironmentInterface);
36+
37+
return $this->environment;
38+
}
39+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Markdown;
4+
5+
use League\CommonMark\Environment\EnvironmentBuilderInterface;
6+
use League\CommonMark\Extension\Autolink\AutolinkExtension;
7+
use League\CommonMark\Extension\ExtensionInterface;
8+
use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
9+
use League\CommonMark\Extension\Table\TableExtension;
10+
use League\CommonMark\Extension\TaskList\TaskListExtension;
11+
12+
final class GithubFlavoredMarkdownExtension implements ExtensionInterface
13+
{
14+
public function register(EnvironmentBuilderInterface $environment): void
15+
{
16+
$environment->addExtension(new AutolinkExtension());
17+
$environment->addExtension(new StrikethroughExtension());
18+
$environment->addExtension(new TableExtension());
19+
$environment->addExtension(new TaskListExtension());
20+
}
21+
}

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"laravel/socialite": "^5.9",
3535
"laravel/telescope": "^5.0",
3636
"laravel/tinker": "^2.8",
37+
"laravel/unfenced": "dev-main",
3738
"orchid/platform": "^14.17",
3839
"overtrue/laravel-like": "^5.2",
3940
"spatie/laravel-activitylog": "^4.7",
@@ -54,6 +55,12 @@
5455
"spatie/laravel-ignition": "^2.0",
5556
"vimeo/psalm": "^5.23"
5657
},
58+
"repositories": [
59+
{
60+
"type": "vcs",
61+
"url": "[email protected]:laravel-labs/unfenced.git"
62+
}
63+
],
5764
"autoload": {
5865
"psr-4": {
5966
"App\\": "app/",

0 commit comments

Comments
 (0)