Skip to content
Prev Previous commit
Next Next commit
Adds initial setup of server-side syntax highlighting
  • Loading branch information
luke-parallax committed Mar 20, 2024
commit f13e928d84f35d33f231df4596a25b8aef09b7dd
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"require": {
"php": "^8.1",
"filament/filament": "^3.0",
"illuminate/contracts": "^10.0",
"spatie/laravel-package-tools": "^1.15.0",
"illuminate/contracts": "^10.0"
"tempest/highlight": "dev-main"
},
"require-dev": {
"laravel/pint": "^1.0",
Expand Down
1 change: 1 addition & 0 deletions resources/css/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../../vendor/filament/filament/resources/css/theme.css';
@import "../../vendor/tempest/highlight/src/Themes/highlight-light-lite.css";

.filament-syntax-entry-component .grid {
@apply block;
Expand Down
6,059 changes: 6,058 additions & 1 deletion resources/dist/filament-syntax-entry.css

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions resources/views/syntax-entry.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ class="filament-syntax-entry"
package: 'parallax/filament-syntax-entry'
))]"
>
<div>
{{-- <pre><code>{{ $$getState() }}</code></pre> --}}
{{ $getState() }}
</div>
<pre>{{ $getValue() }}</pre>
</div>
</x-dynamic-component>
18 changes: 16 additions & 2 deletions src/SyntaxEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
namespace Parallax\FilamentSyntaxEntry;

use Closure;
use Filament\Infolists\Components\Concerns\HasAffixes;
use Filament\Infolists\Components\Concerns;
use Filament\Infolists\Components\Contracts\HasAffixActions;
use Filament\Infolists\Components\Entry;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
use Tempest\Highlight\Highlighter;

class SyntaxEntry extends Entry implements HasAffixActions
{
use HasAffixes;
use Concerns\CanFormatState;
use Concerns\HasAffixes;

protected string $view = 'filament-syntax-entry::syntax-entry';

Expand All @@ -19,6 +23,16 @@ class SyntaxEntry extends Entry implements HasAffixActions

protected string | Closure | null $darkModeTheme = 'filament-dark';

public function getValue(): HtmlString
{
$state = $this->getState();
$language = $this->language;
$toParse = !is_string($state) || $language === 'json' ? json_encode($state, JSON_PRETTY_PRINT) : $state;
$parsed = (new Highlighter())->parse($toParse, 'json');

return Str::of($parsed)->toHtmlString();
}

public function language(string | Closure $language): static
{
$this->language = $language;
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ module.exports = {
],
safelist: [
/syntax-entry-.+/,
/hljs-.+/
/hl-.+/
]
}