Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Torchlight Laravel

Torchlight Laravel Laravel Package

torchlight/torchlight-laravel

Torchlight syntax highlighting for Laravel Blade/Markdown using the Torchlight API. VS Code-compatible highlighting with themes, line highlighting and diffing, no JavaScript required. Includes caching, config publishing, and optional Blade components.

View on GitHub
Deep Wiki
Context7

torchlight/torchlight-laravel integrates the Torchlight API into Laravel to deliver beautiful, VS Code–accurate syntax highlighting without shipping JavaScript. Highlight code blocks in Blade (via components/directives), pick any VS Code theme, and let the client cache rendered output for fast pages.

Perfect for docs, blogs, and apps that need consistent server-rendered code highlighting with minimal setup.

  • Server-side highlighting (no JS required)
  • Supports every language and every VS Code theme
  • Built-in cache driver support to speed up renders
  • Configurable theme, API host, and token via config/torchlight.php
  • Extras like line highlighting and git diffing through Torchlight
Frequently asked questions about Torchlight Laravel
How do I install torchlight/torchlight-laravel in my Laravel project?
Run `composer require torchlight/torchlight-laravel` to install the package. Then publish the config file with `php artisan torchlight:install`, which creates `config/torchlight.php` with default settings like API token, theme, and cache driver.
Does this package work with Laravel 10 or 11?
Yes, the package supports Laravel 8.0–13.x, including Laravel 10 and 11. It’s tested against the latest Laravel versions and integrates with Blade components, Livewire, and Inertia.js seamlessly.
Can I use custom VS Code themes with this package?
Absolutely. Torchlight supports every VS Code theme, including custom ones. Set your preferred theme in `config/torchlight.php` under the `theme` key, or use an environment variable like `TORCHLIGHT_THEME=your-theme-name`.
What happens if the Torchlight API is down or rate-limited?
The package includes fallback mechanisms. For production, implement a local cache (e.g., Redis) with short TTLs or use a static HTML backup. You can also throttle requests or self-host Torchlight if uptime is critical.
How do I highlight code in Blade templates? Is there a directive or component?
Enable Blade components by setting `'blade_components' => true` in `config/torchlight.php`. Then use the `@torchlight` directive or the `torchlight` component in your Blade files, e.g., `<x-torchlight>code here</x-torchlight>`.
Does this package support line highlighting or git diffs?
Yes, Torchlight supports advanced features like line highlighting and git diffs out of the box. Pass options like `highlightLines` or `diff` directly to the API call via the `torchlight()` helper or Block objects.
Can I cache highlighted code blocks for better performance?
Yes, the package integrates with Laravel’s cache drivers (file, Redis, database, etc.). Configure the `cache` key in `config/torchlight.php` to use your preferred driver, and Torchlight will automatically cache rendered blocks.
Is there a way to test this package in my CI pipeline?
The package includes mockable facades for testing. Use `Torchlight::shouldReceive()` to stub API calls in PHPUnit tests. Example: `Torchlight::shouldReceive('highlight')->andReturn('<div>mocked</div>');` for unit tests.
How do I handle dynamic code blocks that change frequently?
For dynamic content, use short cache TTLs or disable caching entirely by setting `'cache' => null`. Alternatively, manually invalidate cache entries via `Cache::forget()` when content updates, especially in multi-user environments.
What are the alternatives if I don’t want to use an external API?
If API dependency is a concern, consider client-side highlighters like Prism.js or Highlight.js for static content. For self-hosted solutions, explore PHP libraries like Rouge (used by Pygments) or build a custom syntax highlighter with Laravel’s service container.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport