tin is a code highlighter for PHP (Terminal, HTML, etc.).
Tests Formats Version Total Downloads License
Requires PHP 8.3+
You can install the package via composer:
composer require felixdorn/tin
A piece of code highlighted using tin
Another piece of code highlighted using tin
Yes, this comes from a terminal.
<?php use Felix\Tin\Themes\JetbrainsDark; use Felix\Tin\Tin; echo Tin::from(JetbrainsDark::class, $ansi = true)->highlight("<?php\n\necho 'Hello world';\n");
You have complete control over the highlighting process. Implement
the Felix\Tin\Contracts\OutputInterface interface or implement a custom theme if
you are just looking to change the colors.
$tin = new \Felix\Tin\Tin( new \Felix\Tin\Outputs\AnsiOutput() )
$tin = new \Felix\Tin\Tin( new \Felix\Tin\Outputs\HtmlOutput() )
Callable output is best used in combination with the ANSI or HTML output, you can think of it as a sort of decorator when you need change a small thing without creating a class.
$tin = new \Felix\Tin\Tin( new \Felix\Tin\Outputs\CallableOutput( new \Felix\Tin\Themes\OneDark(), fn (\Felix\Tin\Line $line) => $line->number % 2 ? (new \Felix\Tin\Outputs\AnsiOutput())->transformLine($line) : null ) )
Themes define the colors used by outputs. The format is r;g;b, to match the default ANSI format.
You need to extend Felix\Tin\Themes\Theme and set the colors to whatever you want.
The color are RGB values separated by a ;.
use Felix\Tin\Contracts\ThemeInterface; use Felix\Tin\Enums\TokenType; class OneDark extends ThemeInterface { /** {@inheritDoc} */ public function color(TokenType $type): string { return match ($type) { TokenType::Keyword => '199;120;221', TokenType::Variable => '224;107;116', TokenType::Comment => '91;98;110', TokenType::String => '152;195;121', TokenType::Function, TokenType::NamedParameter, TokenType::Attribute => '98;174;239', TokenType::Number, TokenType::Html => '229;192;122', default => '171;178;191', }; } }
composer testtin was created by Félix Dorn under the MIT license .