diff --git a/resources/views/filament/infolists/entries/normalized-diff.blade.php b/resources/views/filament/infolists/entries/normalized-diff.blade.php index b3533dd..80f8361 100644 --- a/resources/views/filament/infolists/entries/normalized-diff.blade.php +++ b/resources/views/filament/infolists/entries/normalized-diff.blade.php @@ -105,6 +105,39 @@ } }; + $highlightInline = static function (?string $policyType, string $code) use ($selectGrammar): ?string { + if (! class_exists(\Torchlight\Engine\Engine::class)) { + return null; + } + + if ($code === '') { + return ''; + } + + try { + $html = (new \Torchlight\Engine\Engine())->codeToHtml( + code: $code, + grammar: $selectGrammar($policyType, $code), + theme: [ + 'light' => 'github-light', + 'dark' => 'github-dark', + ], + withGutter: false, + withWrapper: false, + ); + + if (! preg_match('/^
]*>(.*)<\\/code><\\/pre>$/s', $html, $matches)) {
+ return null;
+ }
+
+ $inner = $matches[1] ?? '';
+
+ return trim((string) preg_replace('//', '', $inner));
+ } catch (\Throwable $e) {
+ return null;
+ }
+ };
+
$splitLines = static function (string $text): array {
$text = str_replace(["\r\n", "\r"], "\n", $text);
@@ -248,6 +281,7 @@
$isScriptContent = $canHighlightScripts($policyType) && $isScriptKey($name);
$ops = $isScriptContent ? $scriptLineDiff((string) $fromText, (string) $toText) : [];
+ $useTorchlight = $isScriptContent && class_exists(\Torchlight\Engine\Engine::class);
@endphp
@@ -330,13 +364,32 @@
$leftType = $left['type'];
$leftLine = (string) ($left['line'] ?? '');
+ $leftHighlighted = $useTorchlight ? $highlightInline($policyType, $leftLine) : null;
+ $leftRendered = (is_string($leftHighlighted) && $leftHighlighted !== '') ? $leftHighlighted : e($leftLine);
+
if ($leftType === 'equal') {
- echo e($leftLine)."\n";
+ if ($useTorchlight) {
+ @endphp
+ @once
+ @include('filament.partials.torchlight-dark-overrides')
+ @endonce
+ @php
+ }
+
+ echo $leftRendered."\n";
continue;
}
if ($leftType === 'delete') {
- echo '- '.e($leftLine)."\n";
+ if ($useTorchlight) {
+ @endphp
+ @once
+ @include('filament.partials.torchlight-dark-overrides')
+ @endonce
+ @php
+ }
+
+ echo '- '.$leftRendered."\n";
continue;
}
@@ -353,13 +406,32 @@
$rightType = $right['type'];
$rightLine = (string) ($right['line'] ?? '');
+ $rightHighlighted = $useTorchlight ? $highlightInline($policyType, $rightLine) : null;
+ $rightRendered = (is_string($rightHighlighted) && $rightHighlighted !== '') ? $rightHighlighted : e($rightLine);
+
if ($rightType === 'equal') {
- echo e($rightLine)."\n";
+ if ($useTorchlight) {
+ @endphp
+ @once
+ @include('filament.partials.torchlight-dark-overrides')
+ @endonce
+ @php
+ }
+
+ echo $rightRendered."\n";
continue;
}
if ($rightType === 'insert') {
- echo '+ '.e($rightLine)."\n";
+ if ($useTorchlight) {
+ @endphp
+ @once
+ @include('filament.partials.torchlight-dark-overrides')
+ @endonce
+ @php
+ }
+
+ echo '+ '.$rightRendered."\n";
continue;
}
@@ -372,12 +444,36 @@
Before
- {{ (string) $fromText }}
+ @php
+ $highlightedBefore = $useTorchlight ? $highlight($policyType, (string) $fromText) : null;
+ @endphp
+
+ @if (is_string($highlightedBefore) && $highlightedBefore !== '')
+ @once
+ @include('filament.partials.torchlight-dark-overrides')
+ @endonce
+
+ {!! $highlightedBefore !!}
+ @else
+ {{ (string) $fromText }}
+ @endif
After
- {{ (string) $toText }}
+ @php
+ $highlightedAfter = $useTorchlight ? $highlight($policyType, (string) $toText) : null;
+ @endphp
+
+ @if (is_string($highlightedAfter) && $highlightedAfter !== '')
+ @once
+ @include('filament.partials.torchlight-dark-overrides')
+ @endonce
+
+ {!! $highlightedAfter !!}
+ @else
+ {{ (string) $toText }}
+ @endif
diff --git a/specs/013-scripts-management/tasks.md b/specs/013-scripts-management/tasks.md
index 6ebabbd..332d7c8 100644
--- a/specs/013-scripts-management/tasks.md
+++ b/specs/013-scripts-management/tasks.md
@@ -21,6 +21,7 @@ ## Phase 4: Script Content Display (Safe)
- [x] T009 Highlight script content with Torch (shebang-based shell + PowerShell default).
- [x] T010 Hide script content behind a Show/Hide button (collapsed by default).
- [x] T011 Highlight script content in Normalized Diff view (From/To).
+- [x] T012 Enable Torchlight highlighting in Diff + Before/After views.
## Open TODOs (Follow-up)
- None yet.