swow-cloud / highlighter
dev-master / 3.0.x-dev
2021-12-09 07:24 UTC
This package is auto-updated.
Last update: 2024-12-09 13:50:59 UTC
README
Library, which allows you to highlight your PHP code in terminal
Installation
Installation via composer:
composer require mkgor/highlighter
Printing whole file
<?php require_once "vendor/autoload.php"; $highlighter = new \Highlighter\Highlighter(); echo $highlighter->getWholeFile(__FILE__);
Result
Printing code snippet (and highlighting specified line)
<?php require_once "vendor/autoload.php"; $highlighter = new \Highlighter\Highlighter(); echo $highlighter->getSnippet(__FILE__, 3);
Result
Printing code snippet with specified lines
<?php require_once "vendor/autoload.php"; $highlighter = new \Highlighter\Highlighter(); echo $highlighter->getSpecifiedSnippet(__FILE__, 3, 5);
Result
Printing single line
<?php require_once "vendor/autoload.php"; $highlighter = new \Highlighter\Highlighter(); echo $highlighter->getLine(__FILE__, 3);
Result
You can use same functions with suffix WithoutNumbers
to highlight code without line numbers:
<?php require_once "vendor/autoload.php"; $highlighter = new \Highlighter\Highlighter(); echo $highlighter->getWholeFileWithoutNumbers(__FILE__);
Result
Themes
This highlighter supports custom themes. It has built-in themes, but you can create your own by implementing Highlighter\Theme\ThemeInterface
So, to set theme, just call setTheme
method of Highlighter
<?php require_once "vendor/autoload.php"; $highlighter = new \Highlighter\Highlighter(); $highlighter->setTheme(new Highlighter\Theme\DefaultThemes\Minimalistic()); echo $highlighter->getWholeFile(__FILE__);