Skip to content

Commit

Permalink
Merge pull request #186 from alimranahmed/185-using-tempest-highlight…
Browse files Browse the repository at this point in the history
…-for-code

#185: Code Highlighter Shiki js implementation replaced by tempest/highlighter
  • Loading branch information
alimranahmed authored Aug 28, 2024
2 parents 556cf9a + aae57fa commit 41964b6
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 308 deletions.
20 changes: 16 additions & 4 deletions app/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Spatie\LaravelMarkdown\MarkdownRenderer;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;
use Tempest\Highlight\CommonMark\HighlightExtension;
use Tempest\Highlight\Highlighter;

/**
* @property string $category
Expand Down Expand Up @@ -76,10 +80,18 @@ public function categoryName(): Attribute

public function htmlContent(): Attribute
{
$environment = new Environment();

$highlighter = new Highlighter();

$environment
->addExtension(new CommonMarkCoreExtension())
->addExtension(new HighlightExtension($highlighter));

$markdown = new MarkdownConverter($environment);

return Attribute::make(
get: fn () => app(MarkdownRenderer::class)
->disableHighlighting()
->toHtml($this->content)
get: fn () => $markdown->convert($this->content)
);
}

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
"guzzlehttp/guzzle": "^7.8",
"laravel/framework": "^11.9",
"laravel/tinker": "^2.9",
"league/commonmark": "^2.5",
"livewire/livewire": "^3.4",
"masbug/flysystem-google-drive-ext": "^2.3",
"sentry/sentry-laravel": "^4.4",
"spatie/laravel-backup": "^8.6",
"spatie/laravel-markdown": "^2.5",
"spatie/laravel-permission": "^6.4",
"spatie/laravel-sitemap": "^7.2"
"spatie/laravel-sitemap": "^7.2",
"tempest/highlight": "^2.10"
},
"require-dev": {
"fakerphp/faker": "^1.23",
Expand Down
Loading

0 comments on commit 41964b6

Please sign in to comment.