tempest/highlight
Fast, extensible server-side code highlighting for PHP and more. Tempest Highlight parses source code into highlighted output with a simple API: instantiate the Highlighter and call parse($code, 'php'). Ideal for docs, blogs, and code previews.
@highlight directive for templating.composer validate-autoload.| Risk Area | Mitigation Strategy |
|---|---|
| Lexer/Theme Updates | Pin versions in composer.json; monitor upstream for breaking changes. |
| Memory Usage | Stream large files or implement chunked processing for >1MB inputs. |
| Theme Customization | Abstract theme logic into a config file or Laravel’s config/highlight.php. |
| Real-Time Sync | Use Laravel Echo + Laravel WebSockets for live updates (e.g., VS Code-like editors). |
highlighted_code column (JSON/TEXT) if caching.<pre><code> blocks with @highlight Blade directives.@highlight('php', $codeSnippet, 'dracula')
HighlightService facade:
use Tempest\Highlight\Highlighter;
class HighlightService {
public function highlight(string $code, string $language, string $theme): string {
return app(Highlighter::class)->highlight($code, $language, $theme);
}
}
Route::post('/api/highlight', [HighlightController::class, 'highlight']);
php artisan vendor:publish.| Step | Priority | Dependencies | Output |
|---|---|---|---|
| Install Package | High | Composer | composer require tempest/highlight |
| Blade Directive | Medium | Laravel Blade | Custom @highlight syntax |
| API Endpoint | Medium | Laravel Routing | /api/highlight |
| Caching Layer | Low | Redis/File Cache | Pre-highlighted snippets |
| Real-Time Updates | Low | Laravel Echo + WebSockets | Live editor highlighting |
storage/logs/highlight.log.dd(app(Highlighter::class)->highlight(...)) for troubleshooting.memory_limit (adjust or stream).docs/highlighting.md to your repo with:
memory_limit for large files (e.g., 1G for monorepos).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Highlighter Service Down | Broken UI/API | Fallback to raw code with warning. |
| Lexer Configuration Error | Corrupted output | Validate input languages. |
| Cache Invalidation | Stale highlights | Use cache tags (e.g., highlight:php). |
| PHP Memory Exhaustion | Worker crashes | Implement chunked processing. |
| Theme CSS Conflicts | Rendering issues | Isolate theme CSS in a shadow DOM. |
@highlight Blade syntax and API usage.How can I help you explore Laravel packages today?