tool5 / torchlight-commonmark
Torchlight的Commonmark扩展,语法高亮API。
Requires
- php: ^7.2|^8.0
- league/commonmark: ^1.5|^2.0
- torchlight/torchlight-laravel: ^0.6.0
Requires (Dev)
- mockery/mockery: ^1.3.3
- orchestra/testbench: ^5.0|^6.0
- phpunit/phpunit: ^8.4
This package is auto-updated.
Last update: 2024-09-19 09:10:31 UTC
README
📚 完整文档可以在torchlight.dev/docs/clients/commonmark-php找到。
为PHP League的Commonmark Markdown解析器在Laravel应用程序中提供Torchlight语法高亮扩展。
支持CommonMark版本1和版本2。
Torchlight是一个与VS Code兼容的语法高亮器,无需JavaScript,支持所有语言、所有VS Code主题、行高亮、git diff等。
安装
要安装,请从composer要求包
composer require torchlight/torchlight-commonmark
这将安装Laravel客户端。
添加扩展
如果你使用Graham Campbell的Laravel Markdown包,你可以在markdown.php
文件中的"extensions"键下添加扩展。
'extensions' => [ // Torchlight syntax highlighting TorchlightExtension::class, ],
如果你没有使用Laravel Markdown包,你可以手动添加扩展
// CommonMark V1 $environment = Environment::createCommonMarkEnvironment(); $environment->addExtension(new TorchlightExtension); // CommonMark V2 $environment = new Environment(); $environment->addExtension(new CommonMarkCoreExtension); $environment->addExtension(new TorchlightExtension);
这就是你需要做的!现在你的所有代码围栏都将通过Torchlight进行高亮。
配置
下载包后,你可以运行以下命令发布你的配置文件
php artisan torchlight:install
运行后,你应该会在你的config
文件夹中看到一个名为torchlight.php
的新文件,内容如下
<?php return [ // The Torchlight client caches highlighted code blocks. Here // you can define which cache driver you'd like to use. 'cache' => env('TORCHLIGHT_CACHE_DRIVER'), // Which theme you want to use. You can find all of the themes at // https://torchlight.dev/themes, or you can provide your own. 'theme' => env('TORCHLIGHT_THEME', 'material-theme-palenight'), // Your API token from torchlight.dev. 'token' => env('TORCHLIGHT_TOKEN'), // If you want to register the blade directives, set this to true. 'blade_components' => true, // The Host of the API. 'host' => env('TORCHLIGHT_HOST', 'https://api.torchlight.dev'), ];
缓存
设置Torchlight将使用的缓存驱动器。
主题
你可以通过调整配置中的theme
键来更改所有代码块的样式。
令牌
这是从torchlight.dev获取的API令牌。(Torchlight对个人和开源项目完全免费。)
Blade组件
默认情况下,Torchlight通过使用一个自定义Laravel组件来工作。如果你出于任何原因想要禁用组件的注册,可以将此设置为false。
主机
你可以更改API请求发送的主机。不清楚你为什么要这么做,但你可以!