decodelabs / enlighten
PHP source highlighter
Installs: 14 405
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- decodelabs/coercion: ^0.2
- decodelabs/exceptional: ^0.4
Requires (Dev)
README
PHP source highlighter
Enlighten provides exhaustive and accurate PHP source highlighting for use in debugging systems.
Get news and updates on the DecodeLabs blog.
Installation
Install using Composer:
composer require decodelabs/enlighten
Usage
Enlighten uses the PHP tokenizer extension which requires the full source from file (including <?php
open tag).
It is effectively a more thorough version of highlight_string
and highlight_file
- grammar is properly wrapped and name entities are parsed according to their surrounding tokens to work out what type they are (function name, class name, etc, etc).
Enlighten also offers the ability to extract certain portions of the code and focus on a specific line. Line numbers are included in the output HTML to aid in readability.
use DecodeLabs\Enlighten\Highlighter; $highlighter = new Highlighter(); echo $highlighter->highlight($phpSourceCode); // Highlight source code in memory echo $highlighter->highlightFile($phpFile, 15, 35, 20); // Highlight specific lines (15 to 35) in file (focus on 20) echo $highlighter->extract($phpSourceCode, 20); // Extract code around specific line echo $highlighter->extractFromFile($phpFile, 20); // Extract code around specific line
Licensing
Enlighten is licensed under the MIT License. See LICENSE for the full license text.