Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 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.

```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.