Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/decodelabs/enlighten
PHP source highlighter
https://github.com/decodelabs/enlighten
php source-highlight
Last synced: 1 day ago
JSON representation
PHP source highlighter
- Host: GitHub
- URL: https://github.com/decodelabs/enlighten
- Owner: decodelabs
- License: mit
- Created: 2019-09-29T23:34:29.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2024-09-04T21:03:47.000Z (4 months ago)
- Last Synced: 2024-12-18T11:28:37.691Z (22 days ago)
- Topics: php, source-highlight
- Language: PHP
- Homepage:
- Size: 68.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Enlighten
[![PHP from Packagist](https://img.shields.io/packagist/php-v/decodelabs/enlighten?style=flat)](https://packagist.org/packages/decodelabs/enlighten)
[![Latest Version](https://img.shields.io/packagist/v/decodelabs/enlighten.svg?style=flat)](https://packagist.org/packages/decodelabs/enlighten)
[![Total Downloads](https://img.shields.io/packagist/dt/decodelabs/enlighten.svg?style=flat)](https://packagist.org/packages/decodelabs/enlighten)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/decodelabs/enlighten/integrate.yml?branch=develop)](https://github.com/decodelabs/enlighten/actions/workflows/integrate.yml)
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-44CC11.svg?longCache=true&style=flat)](https://github.com/phpstan/phpstan)
[![License](https://img.shields.io/packagist/l/decodelabs/enlighten?style=flat)](https://packagist.org/packages/decodelabs/enlighten)### PHP source highlighter
Enlighten provides exhaustive and accurate PHP source highlighting for use in debugging systems.
_Get news and updates on the [DecodeLabs blog](https://blog.decodelabs.com)._
---
## Installation
Install using Composer:
```bash
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
andhighlight_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.
```php
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](./LICENSE) for the full license text.