https://github.com/adhocore/php-cli-syntax
PHP Code Syntax Highlighter and/or exporter for CLI. Zero Dependency.
https://github.com/adhocore/php-cli-syntax
adhocore cli-syntax cli-syntax-highlight code-screenshot code-to-image export-php-code php php-code-highlight php7 syntax-highlighting
Last synced: about 2 months ago
JSON representation
PHP Code Syntax Highlighter and/or exporter for CLI. Zero Dependency.
- Host: GitHub
- URL: https://github.com/adhocore/php-cli-syntax
- Owner: adhocore
- License: mit
- Created: 2019-12-20T23:02:47.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-05-21T14:29:41.000Z (about 2 years ago)
- Last Synced: 2025-04-15T06:17:28.341Z (about 2 months ago)
- Topics: adhocore, cli-syntax, cli-syntax-highlight, code-screenshot, code-to-image, export-php-code, php, php-code-highlight, php7, syntax-highlighting
- Language: PHP
- Homepage: https://github.com/adhocore/php-cli-syntax
- Size: 505 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
## adhocore/cli-syntax
[](https://github.com/adhocore/php-cli-syntax/releases)
[](https://travis-ci.com/adhocore/php-cli-syntax?branch=master)
[](https://scrutinizer-ci.com/g/adhocore/php-cli-syntax/?branch=master)
[](https://codecov.io/gh/adhocore/php-cli-syntax)
[](https://styleci.io/repos/229348504)
[](./LICENSE)```
_ _ _
___ | | (_) ___ | |__
/ __| | | | | / __| ' _ \
| (__ | | | | \___ \ | | | |
\___| |_| |_| |____/ |_| |_|PHP CLI Syntax Highlight Tool
=============================
```## Installation
### As phar binary
```sh
curl -SsLo ~/clish.phar https://github.com/adhocore/php-cli-syntax/releases/latest/download/clish.pharchmod +x ~/clish.phar && sudo ln -s ~/clish.phar /usr/local/bin/clish
```
> Follow same steps to upgrade.### As standalone binary
```sh
composer global require adhocore/cli-syntax
```
> Follow same steps to upgrade.### As project dependency
```bash
composer require adhocore/cli-syntax
```## Usage
### Shell command
If you installed as binary following any of the above methods, then:
```sh
# you will be able to run it as
clish -h
clish -f file.php
echo ' `clish` stands for CLI syntax highlight.#### Options
Parameter options:
```
[-e|--echo] Forces echo to STDOUT when --output is passed
[-f|--file] Input PHP file to highlight and/or export
(will read from piped input if file not given)
[-F|--font] Font to use for export to png
[-l|--with-line-no] Highlight with line number
[-o|--output] Output filepath where PNG image is exported
```> Run `clish -h` to show help.
##### Examples
```sh
bin/clish --file file.php # print
cat file.php | bin/clish # from piped stream
bin/clish < file.php # from redirected stdin
bin/clish --file file.php --output file.png # export
bin/clish --file file.php --output file.png --echo # print + export
bin/clish --file file.php --with-line-no # print with lineno
bin/clish -f file.php -o file.png -F dejavu # export in dejavu font
```### Programatically
You can either highlight PHP code in terminal output or export to png image.
#### Highlight
```php
use Ahc\CliSyntax\Highlighter;// PHP code
echo new Highlighter('highlight(' true, // bool
];
```#### Export
```php
use Ahc\CliSyntax\Exporter;// PHP file
Exporter::for('/path/to/file.php')->export('file.png', $options);// $options array is optional and can contain:
[
'lineNo' => true, // bool
'font' => 'full/path/of/font.ttf', // str
'size' => 'font size', // int
];
```See [example usage](./example.php). Here's how the export looks like:

---
And with line numbers:
## Customisation
If you would like to change color etc, extend the classes
[`Highlighter`](./src/Highlighter.php) and [`Exporter`](./src/Exporter.php),
then override `visit()` method which recieves [`DOMNode`](https://php.net/DOMNode).## Contributing
Please check [the guide](./CONTRIBUTING.md).
## LICENSE
> © [MIT](./LICENSE) | 2019, Jitendra Adhikari
## Credits
This project is bootstrapped by [phint](https://github.com/adhocore/phint)
and releases managed by [please](https://github.com/adhocore/please).