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

https://github.com/sokil/php-diff

Highlight diffs provided by Sebastian Bergmann diff
https://github.com/sokil/php-diff

diff diff-highlight highlight php

Last synced: 12 months ago
JSON representation

Highlight diffs provided by Sebastian Bergmann diff

Awesome Lists containing this project

README

          

# php-diff

Highlight diffs provided by Sebastian Bergmann diff

[![Build Status](https://travis-ci.org/sokil/php-diff.svg?branch=master)](https://travis-ci.org/sokil/php-diff)
[![Coverage Status](https://coveralls.io/repos/github/sokil/php-diff/badge.svg?branch=master&1)](https://coveralls.io/github/sokil/php-diff?branch=master)
[![Total Downloads](http://img.shields.io/packagist/dt/sokil/php-diff.svg?1)](https://packagist.org/packages/sokil/php-diff)

## Installation

```
composer.phar require sokil/php-diff
```

## Useage

```php
render(new Change(
implode(PHP_EOL, ['line1', 'line2', 'line3']),
implode(PHP_EOL, ['line1', 'line2changed', 'line3'])
));

```

## Format of diff output

Format of diff tags may be configured. By default renders only two tags: `` and ``. To
highlight output, use predefined format:

```php
Renderer::FORMAT_COLOUR
]);
```

This will produce following HTML:

```html
line1
line2
line2changed
line3
```

To fully customize style, use next syntax (this format has alias `Renderer::FORMAT_COLOUR`):

```php
[
'insert' => [
'tag' => 'ins',
'attributes' => 'style="background: #ddfade;"',
],
'delete' => [
'tag' => 'del',
'attributes' => 'style="background: #ffe7e7;"',
]
]
]);

// this is same to
$renderer = new Renderer([
'format' => Renderer::FORMAT_COLOUR
]);
```

Default format `Renderer::FORMAT_DEFAULT` has following notation:

```php
[
'tag' => 'ins',
],
'delete' => [
'tag' => 'del',
]
]);

// this is same to
$renderer = new Renderer([
'format' => Renderer::FORMAT_DEFAULT
]);
```