Customization

Syntax Highlighting with Torchlight

This guide will walk you through adding syntax highlighting to your Prezet blog using Torchlight, a fast and versatile syntax highlighter supporting over 100 languages and themes.

You can see Torchlight in action throughout this site, as all code snippets on prezet.com are rendered via the Torchlight API.

#Install the Torchlight Package

Begin by installing the Torchlight CommonMark package:

1composer require torchlight/torchlight-commonmark

#Configure the Torchlight Markdown Extension

To enable Torchlight in your Prezet blog, add the Torchlight extension to your config/prezet.php file:

1'commonmark' => [
2 'extensions' => [
3 League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension::class,
4 League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension::class,
5 League\CommonMark\Extension\ExternalLink\ExternalLinkExtension::class,
6 League\CommonMark\Extension\FrontMatter\FrontMatterExtension::class,
7 BenBjurstrom\Prezet\Extensions\MarkdownBladeExtension::class,
8 BenBjurstrom\Prezet\Extensions\MarkdownImageExtension::class,
9 Torchlight\Commonmark\V2\TorchlightExtension::class,
10 ],
11 // ... other configuration options
12],

#Obtain and Configure Your Torchlight API Key

To use Torchlight, you'll need an API key:

  1. Visit app.torchlight.dev/register to create an account.
  2. Create a new project in your Torchlight dashboard.
  3. Copy the provided API key.

Add the API key to your .env file:

1TORCHLIGHT_TOKEN=your-api-key

#Using Torchlight in Your Content

With Torchlight set up, you can now use syntax highlighting in your Markdown files. Simply specify the language after the opening triple backticks:

1```php
2public function handle()
3{
4 // Your PHP code here
5}
6```

Torchlight will automatically apply syntax highlighting to your code blocks turning the above markdown into this:

1public function handle()
2{
3 // Your PHP code here
4}

#Attribution

If you're using Torchlight's free plan, make sure to include attribution on your site. You can find more information about attribution requirements in the Torchlight documentation.