Skip to content

Instantly share code, notes, and snippets.

@duncanmcclean
Created May 26, 2022 08:04
Show Gist options
  • Save duncanmcclean/18f0ba9de48f086d51f8f9b631bc70cc to your computer and use it in GitHub Desktop.
Save duncanmcclean/18f0ba9de48f086d51f8f9b631bc70cc to your computer and use it in GitHub Desktop.
<div class="my-2 w-full torchlight-parent">
{{ torchlight :language="language" }}
{{ code | noparse | entities }}
{{ /torchlight }}
</div>
<?php
namespace App\Tags;
use Statamic\Tags\Tags;
use Torchlight\Blade\BladeManager;
use Torchlight\Block;
class Torchlight extends Tags
{
/**
* {{ torchlight language="php" }}{{ my_code }}{{ /torchlight }}
*/
public function index()
{
$language = $this->params->get('language');
$code = $this->context->raw('code');
$block = Block::make()
->language($language)
->code($code)
->theme(config('torchlight.theme'));
BladeManager::registerBlock($block);
$render = function (Block $block) {
return "<pre><code class='{$block->placeholder('classes')}' style='{$block->placeholder('styles')}'>{$block->placeholder()}</code></pre>";
};
return $render($block);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment