The CommonMark PHP Client is an extension for the excellent League\Commonmark package.
To install, require the package from composer:
1composer require torchlight/torchlight-commonmark
This will install the Laravel Client as well.
If you are using Graham Campbell's Laravel Markdown package, you can add the extension in your markdown.php
file, under the "extensions" key.
1'extensions' => [2 // Torchlight syntax highlighting3 TorchlightExtension::class,4],
If you aren't using the Laravel Markdown package, you can add the extension manually:
1$environment = Environment::createCommonMarkEnvironment();2$environment->addExtension(new TorchlightExtension);
That's all you need to do! All of your code fences will now be highlighted via Torchlight.
Once the package is downloaded, you can run the following command to publish your configuration file:
1php artisan torchlight:install
To read about all the configuration options available in your torchlight.php
file, head over to the Laravel client documentation.
To set the language of a code block, set the key of the language after the three backticks:
1```php2echo "This is php!";3```45```js6console.log("This is javascript!")7```
1echo "This is php!";
1console.log("This is javascript!")
Your global theme is controlled by your torchlight.php
file, but if you want to change a single block you can pass the key of a theme using the theme:key
attribute after the language:
1```php theme:winter-is-coming-dark2echo "Winter is coming, dark!";3```45```js theme:winter-is-coming-blue6console.log("Winter is coming, blue!")7```
1echo "Winter is coming, dark!";
1console.log("Winter is coming, blue!")