- How do I integrate Tempest/Highlight into Laravel Blade templates?
- Use a custom Blade directive like `@highlight('php', $code, 'dracula')` for inline syntax highlighting. Register the directive in a service provider by binding the `Highlighter` class to Laravel’s container. This works seamlessly with Livewire or Alpine.js for dynamic updates.
- Can Tempest/Highlight replace client-side tools like Prism.js for Laravel APIs?
- Yes. Tempest/Highlight is server-side, so it eliminates client-side latency and works perfectly for API responses. Return highlighted JSON payloads directly from Laravel routes or middleware, reducing frontend complexity.
- What Laravel versions and PHP versions does Tempest/Highlight support?
- Tempest/Highlight requires PHP 8.1+ and is fully compatible with Laravel 9, 10, and 11. It leverages modern PHP features like attributes and enums, so ensure your Laravel app meets these requirements.
- How can I cache highlighted code to improve performance in high-traffic apps?
- Use Laravel’s cache drivers (Redis, file, or database) to store highlighted output. For static content, pre-highlight snippets and cache them for minutes/hours. For dynamic content, cache per-user or per-language themes.
- Does Tempest/Highlight support custom languages or DSLs (Domain-Specific Languages)?
- Absolutely. The package is extensible—you can create custom lexers for niche languages or DSLs. Follow the `Lexer` interface and register your lexer via the service provider. Themes can also be customized to match your brand.
- How do I handle large code files (e.g., GitHub-style repositories) without memory issues?
- For files over 1MB, use Laravel Queues to offload highlighting to background jobs. Process files in chunks or stream them to avoid memory spikes. Tempest/Highlight is optimized for performance, but chunking ensures scalability.
- What’s the best way to test Tempest/Highlight in Laravel?
- Use Pest or Laravel’s built-in testing tools to mock lexers and verify Blade/API outputs. Test edge cases like invalid code snippets or unsupported languages. For integration tests, simulate real-world usage with Livewire or API routes.
- Can I use Tempest/Highlight with Livewire or Alpine.js for real-time updates?
- Yes. Highlight code server-side in Laravel, then push updates to the client via Livewire or Alpine.js. For collaborative editors, combine Tempest/Highlight with Laravel WebSockets or Laravel Echo to sync changes instantly.
- Are there alternatives to Tempest/Highlight for Laravel, and why should I choose it?
- Alternatives like Highlight.js (client-side) or Prism.js add latency and require JavaScript. Tempest/Highlight is PHP-native, faster, and integrates directly into Laravel’s ecosystem. It’s ideal for headless APIs, server-rendered apps, or high-performance needs.
- How do I publish or customize themes/lexers for Tempest/Highlight in Laravel?
- Run `php artisan vendor:publish` to publish default themes/lexers to `config/highlight.php`. Override them in your app’s config or create new lexers by extending the `Lexer` class. The package supports CSS themes, so align them with your Laravel app’s design system.