1. Go to this page and download the library: Download torchlight/engine library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;
use Torchlight\Engine\CommonMark\Extension;
$environment = new Environment;
$environment
->addExtension(new CommonMarkCoreExtension)
->addExtension(new Extension('github-light'));
$converter = new MarkdownConverter($environment);
$output = $converter->convert(<<<'MD'
use Torchlight\Engine\CommonMark\Extension;
$extension = new Extension('github-light');
$extension->renderer()
->setDefaultGrammar('php');
namespace Torchlight\Engine\CommonMark;
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
interface BlockCache
{
public function has(FencedCode $node): bool;
public function get(FencedCode $node): string;
public function set(FencedCode $node, string $result): void;
}
use Torchlight\Engine\CommonMark\Extension;
$extension = new Extension('github-light');
$extension->renderer()
->setBlockCache(new MyCacheImplementation);
use Torchlight\Engine\CommonMark\Extension;
echo str()->markdown('...your markdown content...', extensions: [
new Extension('github-light'),
]);
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Statamic\Facades\Markdown;
use Torchlight\Engine\CommonMark\Extension;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
// Add the Torchlight Engine extension
Markdown::addExtension(function () {
return new Extension('synthwave-84');
});
}
}
use Torchlight\Engine\Engine;
$engine = new Engine;
$code = <<<'PHP'
echo "Hello, world!"; // [tl! ++]
PHP;
$engine->codeToHtml(
$code, // The code to highlight
'php', // The language
'github-light' // The theme(s) to use
);
use Torchlight\Engine\CommonMark\Extension;
$extension = new Extension([
'light' => 'github-light',
'dark' => 'github-dark',
]);
use Torchlight\Engine\Engine;
$engine = new Engine;
$engine->registerTheme('my-theme', '/path/to/my-theme.json');
echo $engine->codeToHtml('echo "hello";', 'php', 'my-theme');
// This is a long bit of text, hard to highlight the middle. [tl! highlight:6,3]
return <<<EOT
spring sunshine
the smell of waters
from the stars
deep winter
the smell of a crow
from the stars
beach to school
the smell of water
in the sky
EOT;
// This is a long bit of text, hard to highlight the middle.
return <<<EOT
spring sunshine
the smell of waters
from the stars
deep winter
the smell of a crow
from the stars
beach to school
the smell of water
in the sky
EOT; // [tl! highlight:-7,3]
return [
'extensions' => [ // Start here [tl! highlight:start]
// Add attributes straight from markdown.
AttributesExtension::class,
// Add Torchlight syntax highlighting.
TorchlightExtension::class,
] // End here [tl! highlight:end]
]
// Reach down 4 lines, add the ID to one line [tl! #popover-trigger:4,1]
return <<<EOT
spring sunshine
the smell of waters
from the stars
deep winter
the smell of a crow
from the stars
beach to school
the smell of water
in the sky
EOT;
use Torchlight\Engine\Options;
Options::setDefaultOptionsBuilder(function () {
return new Options(
// Specify your options here.
);
});
use Torchlight\Engine\Options;
Options::setDefaultOptionsBuilder(function () {
return Options::fromArray([]);
});
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Torchlight\Engine\Options;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Options::setDefaultOptionsBuilder(fn () => Options::fromArray(config('torchlight.options')));
}
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Torchlight\Engine\CommonMark\Extension;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Extension::setThemeResolver(function () {
return config('torchlight.theme');
});
}
}
// torchlight! {"copyable": true}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Statamic\Facades\Markdown;
use Torchlight\Engine\CommonMark\Extension;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
// Add the Torchlight Engine extension
Markdown::addExtension(function () {
return new Extension('synthwave-84');
});
}
}
use Torchlight\Engine\Engine;
use Torchlight\Engine\Annotations\AnnotationContext;
$engine = new Engine;
$engine->registerAnnotation('important', function (AnnotationContext $ctx) {
$ctx->addBlockClass('has-important-lines')
->addLineClass('line-important');
});
$engine->registerAnnotation('badge', function (AnnotationContext $ctx) {
if ($ctx->isCharacterRange()) {
$ctx->addClassToCharacterRange('badge');
} else {
$ctx->addLineClass('line-badge');
}
}, charRanges: true);
use Torchlight\Engine\Contracts\TokenTransformer;
use Torchlight\Engine\Generators\RenderContext;
$engine->registerTokenTransformerFactory(function () {
return new class implements TokenTransformer {
public function transform(RenderContext $context, array $tokens): array
{
// Modify tokens here
return $tokens;
}
public function supports(string $grammarName): bool
{
return $grammarName === 'my-grammar';
}
};
});
use Torchlight\Engine\Contracts\BlockDecorator;
use Torchlight\Engine\Generators\RenderContext;
$engine->registerBlockDecoratorFactory(function () {
return new class implements BlockDecorator {
public function shouldRender(RenderContext $context): bool
{
return true;
}
public function render(RenderContext $context, string $cleanedText): string
{
return '<div class="my-footer">Custom content</div>';
}
public function getPriority(): int
{
return 100;
}
};
});
use Torchlight\Engine\Contracts\Preprocessor;
use Torchlight\Engine\Engine;
use Torchlight\Engine\Preprocessors\PreprocessorArgs;
class MyPreprocessor implements Preprocessor
{
public function process(PreprocessorArgs $args, Engine $engine): array
{
return $args->tokens;
}
public function supports(?string $grammarName): bool
{
return true;
}
}