torchlight / torchlight-jigsaw
为静态站点生成器Jigsaw的Torchlight客户端
Requires
- tightenco/jigsaw: ^1.3.27
- torchlight/torchlight-laravel: ^0.5.10
Requires (Dev)
- phpunit/phpunit: ^8.4
README
为静态站点构建器Jigsaw提供的Torchlight语法高亮扩展。
Torchlight是一个兼容VS Code的语法高亮器,无需JavaScript,支持所有语言、所有VS Code主题、行高亮、git diff等。
📚 完整文档可以在torchlight.dev/docs/clients/jigsaw找到。
安装
要安装,从composer中要求包
composer require torchlight/torchlight-jigsaw
下载包后,将以下行添加到您的bootstrap.php
Torchlight\Jigsaw\TorchlightExtension::make($container, $events)->boot();
这将启动扩展,以便它可以注册其绑定、事件和命令。
现在您的bootstrap.php
可能看起来像这样
<?php use App\Listeners\GenerateSitemap; use TightenCo\Jigsaw\Jigsaw; /** @var $container \Illuminate\Container\Container */ /** @var $events \TightenCo\Jigsaw\Events\EventBus */ /** * You can run custom code at different stages of the build process by * listening to the 'beforeBuild', 'afterCollections', and 'afterBuild' events. * * For example: * * $events->beforeBuild(function (Jigsaw $jigsaw) { * // Your code here * }); */ $events->afterBuild(GenerateSitemap::class); Torchlight\Jigsaw\TorchlightExtension::make($container, $events)->boot();
配置
要配置您的Torchlight集成,您可以首先发布配置文件
./vendor/bin/jigsaw torchlight:install
运行后,您应该在项目的根目录下看到一个名为torchlight.php
的新文件,内容如下
return [ // 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' => 'material-theme-palenight', // Your API token from torchlight.dev. 'token' => '', // If you want to register the blade directives, set this to true. 'blade_components' => true, // The Host of the API. 'host' => 'https://api.torchlight.dev', // If you want to specify the cache path, you can do so here. Note // that you should *not* use the same path that Jigsaw uses, // which is `cache` at the root level of your app. 'cache_path' => 'torchlight_cache', ];
主题
您可以通过调整配置中的theme
键来更改所有代码块的主题。
令牌
这是您从torchlight.dev获得的API令牌。(Torchlight对个人和开源项目完全免费。)
Blade组件
默认情况下,Torchlight与Markdown文件以及Blade文件一起工作,使用自定义Laravel组件。如果您出于任何原因想要禁用组件的注册,可以将此设置为false。
主机
您可以将API请求发送到的主机更改。不确定您为什么要这样做,但您可以!
缓存
Torchlight需要一个独立的缓存路径,与Jigsaw的缓存不同。Jigsaw会不时清理其缓存,而Torchlight则依赖于Laravel缓存驱动器的单个TTL。
您可能希望将配置的缓存路径(
/torchlight_cache/
)添加到您的.gitignore
文件中,以便缓存文件不会持久化到您的git历史中。
用法
Markdown
要在您的Jigsaw markdown文件中使用Torchlight,您除了使用您已经使用的代码块之外不需要做任何事情。
This is my great markdown file! I'm going to show some code now: ```php echo "here is my code" ``` Wasn't that good code?
Torchlight将处理该代码块的高亮显示。
如果您想要添加额外的类或ID,可以使用Jigsaw的底层markdown解析器支持的语法。
This is my great markdown file! I'm going to show some code now: ```php {#some-html-id.mt-4.mb-8} echo "here is my code" ``` Wasn't that good code?
生成的code
元素将有一个ID为some-html-id
,类为mt-4 mb-8
,以及Torchlight应用的所有类。
Blade
如果您想在.blade.php
文件中使用Torchlight,可以使用自定义blade组件x-torchlight-code
。
<pre><x-torchlight-code language='php'> echo "hello world"; </x-torchlight-code></pre>
您可以添加任何类或其他属性,并且它们将被保留
<pre><x-torchlight-code id='hello-world' class='mt-4 mb-8' language='php'> echo "hello world"; </x-torchlight-code></pre>