|
1 | 1 | # Laravel Torchlight Extension for Commonmark |
2 | 2 |
|
3 | | -[](https://github.com/torchlight-api/torchlight-commonmark-php/actions/workflows/tests.yml) [](//packagist.org/packages/torchlight/torchlight-commonmark) [](//packagist.org/packages/torchlight/torchlight-commonmark) [](//packagist.org/packages/torchlight/torchlight-commonmark) |
| 3 | +[](https://github.com/torchlight-api/torchlight-commonmark-php/actions/workflows/tests.yml) [](//packagist.org/packages/torchlight/torchlight-commonmark) [](//packagist.org/packages/torchlight/torchlight-commonmark) [](//packagist.org/packages/torchlight/torchlight-commonmark) |
| 4 | + |
| 5 | + |
| 6 | +A [Torchlight](https://torchlight.dev) syntax highlighting extension for the PHP League's [Commonmark Markdown Parser](https://commonmark.thephpleague.com/) in a Laravel application. |
| 7 | + |
| 8 | +Torchlight is a VS Code-compatible syntax highlighter that requires no JavaScript, supports every language, every VS Code theme, line highlighting, git diffing, and more. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +To install, require the package from composer: |
| 13 | + |
| 14 | +``` |
| 15 | +`composer require torchlight/torchlight-commonmark` |
| 16 | +``` |
| 17 | + |
| 18 | +This will install the [Laravel Client](https://github.com/torchlight-api/torchlight-laravel) as well. |
| 19 | + |
| 20 | +## Adding the Extension |
| 21 | + |
| 22 | +If you are using Graham Campbell's [Laravel Markdown](https://github.com/GrahamCampbell/Laravel-Markdown) package, you can add the extension in your `markdown.php` file, under the "extensions" key. |
| 23 | + |
| 24 | +```php |
| 25 | +'extensions' => [ |
| 26 | + // Torchlight syntax highlighting |
| 27 | + TorchlightExtension::class, |
| 28 | +], |
| 29 | +``` |
| 30 | + |
| 31 | +If you aren't using the Laravel Markdown package, you can add the extension manually: |
| 32 | + |
| 33 | +```php |
| 34 | +$environment = Environment::createCommonMarkEnvironment(); |
| 35 | +$environment->addExtension(new TorchlightExtension); |
| 36 | +``` |
| 37 | + |
| 38 | +*That's all you need to do! All of your code fences will now be highlighted via Torchlight.* |
| 39 | + |
| 40 | +## Configuration |
| 41 | + |
| 42 | +Once the package is downloaded, you can run the following command to publish your configuration file: |
| 43 | + |
| 44 | +``` |
| 45 | +php artisan torchlight:install |
| 46 | +``` |
| 47 | + |
| 48 | +Once run, you should see a new file `torchlight.php` in you `config` folder, with contents that look like this: |
| 49 | + |
| 50 | +```php |
| 51 | +<?php |
| 52 | +return [ |
| 53 | + // The Torchlight client caches highlighted code blocks. Here |
| 54 | + // you can define which cache driver you'd like to use. |
| 55 | + 'cache' => env('TORCHLIGHT_CACHE_DRIVER'), |
| 56 | + |
| 57 | + // Which theme you want to use. You can find all of the themes at |
| 58 | + // https://torchlight.dev/themes, or you can provide your own. |
| 59 | + 'theme' => env('TORCHLIGHT_THEME', 'material-theme-palenight'), |
| 60 | + |
| 61 | + // Your API token from torchlight.dev. |
| 62 | + 'token' => env('TORCHLIGHT_TOKEN'), |
| 63 | + |
| 64 | + // If you want to register the blade directives, set this to true. |
| 65 | + 'blade_components' => true, |
| 66 | + |
| 67 | + // The Host of the API. |
| 68 | + 'host' => env('TORCHLIGHT_HOST', 'https://api.torchlight.dev'), |
| 69 | +]; |
| 70 | +``` |
| 71 | +### Cache |
| 72 | + |
| 73 | +Set the cache driver that Torchlight will use. |
| 74 | + |
| 75 | +### Theme |
| 76 | + |
| 77 | +You can change the theme of all your code blocks by adjusting the `theme` key in your configuration. |
| 78 | + |
| 79 | +### Token |
| 80 | + |
| 81 | +This is your API token from [torchlight.dev](https://torchlight.dev). (Torchlight is completely free for personal and open source projects.) |
| 82 | + |
| 83 | +### Blade Components |
| 84 | + |
| 85 | +By default Torchlight works by using a [custom Laravel component](https://laravel.com/docs/master/blade#components). If you'd like to disable the registration of the component for whatever reason, you can turn this to false. |
| 86 | + |
| 87 | +### Host |
| 88 | + |
| 89 | +You can change the host where your API requests are sent. Not sure why you'd ever want to do that, but you can! |
| 90 | + |
0 commit comments