-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSyntaxEntry.php
69 lines (52 loc) · 1.68 KB
/
SyntaxEntry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Parallax\FilamentSyntaxEntry;
use Closure;
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 Concerns\CanFormatState;
use Concerns\HasAffixes;
protected string $view = 'filament-syntax-entry::syntax-entry';
protected string | Closure | null $language = 'json';
protected string | Closure | null $theme = 'filament';
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, $language);
return Str::of($parsed)->toHtmlString();
}
public function language(string | Closure $language): static
{
$this->language = $language;
return $this;
}
public function getLanguage(): string
{
return $this->evaluate($this->language);
}
public function theme(string | Closure $theme): static
{
$this->theme = $theme;
return $this;
}
public function getTheme(): string
{
return $this->evaluate($this->theme);
}
public function darkModeTheme(string | Closure $darkModeTheme): static
{
$this->darkModeTheme = $darkModeTheme;
return $this;
}
public function getDarkModeTheme(): string | null
{
return $this->evaluate($this->darkModeTheme);
}
}