Skip to content

Digi live #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@

## Introduction

A comprehensive library for generating differences between
two hashable objects (strings or arrays). Generated differences can be
rendered in all of the standard formats including:
A comprehensive library for generating differences between two hashable objects (strings or arrays).
Generated differences can be rendered in all of the standard formats including:
* Unified
* Context
* Inline HTML
* Side by Side HTML
* Unified HTML

The logic behind the core of the diff engine (ie, the sequence matcher)
is primarily based on the Python difflib package. The reason for doing
so is primarily because of its high degree of accuracy.

The logic behind the core of the diff engine (ie, the sequence matcher) is primarily based on the Python difflib
package. The reason for doing so is primarily because of its high degree of accuracy.

## Install

Expand All @@ -42,40 +39,42 @@ $b = file_get_contents(dirname(__FILE__).'/b.txt');

// Options for generating the diff.
$options = [
//'ignoreWhitespace' => true,
//'ignoreCase' => true,
'ignoreWhitespace' => true,
'ignoreCase' => true,
'context' => 2,
];

// Initialize the diff class.
$diff = new \jblond\Diff($a, $b, $options);
$diff = new \jblond\Diff($a, $b /*, $options */);

// Choose Renderer.
$renderer = new \jblond\Diff\Renderer\Html\SideBySide([
'title_a' => 'Custom title for OLD version',
'title_b' => 'Custom title for NEW version',
'title1' => 'Custom title for OLD version',
'title2' => 'Custom title for NEW version',
]);

// Show it.
echo $diff->Render($renderer);
```

### Example Output
A quick usage example can be found in the example/ directory and under
example.php.

![Example Image](readme.png "Example")
A quick usage example can be found in the `example/` directory and under example.php.

![Example 2 Image](readme2.png "Example2")
![HTML Side By Side Example](htmlSideBySide.png "HTML Side By Side Example")
![HTML Inline Example](htmlInline.png "HTML Inline Example")
![HTML Unified Example](htmlUnified.png "HTML Unified Example")
![Text Unified Example](textUnified.png "Text Unified Example")
![Text Context Example](textContext.png "Text Context Example")

## Requirements

* PHP 7.2 or greater
* PHP Multibyte String
* PHP Multibyte String

## Merge files using jQuery

Xiphe has build a jQuery plugin with that you can merge the compared
files. Have a look at [jQuery-Merge-for-php-diff](https://github.com/Xiphe/jQuery-Merge-for-php-diff).
Xiphe has build a jQuery plugin with that you can merge the compared files.
Have a look at [jQuery-Merge-for-php-diff](https://github.com/Xiphe/jQuery-Merge-for-php-diff).

## Todo

Expand Down
84 changes: 45 additions & 39 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
{
"name" : "jblond/php-diff",
"type" : "library",
"description" : "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
"license" : "BSD-3-Clause",
"keywords" : [
"php",
"diff"
],
"authors" : [{
"name" : "Mario",
"email" : "[email protected]"
}, {
"name" : "Chris Boulton",
"email" : "[email protected]"
}
],
"require" : {
"php" : ">=7.2",
"ext-mbstring" : "*"
},
"require-dev" : {
"phpunit/phpunit" : "8.*",
"squizlabs/php_codesniffer" : "*",
"phpmd/phpmd": "2.*"
},
"autoload" : {
"psr-4" : {
"jblond\\" : "lib/jblond"
}
},
"config" : {
"classmap-authoritative" : true
},
"scripts" : {
"phpunit" : "phpunit ./tests/",
"php_src" : "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
"php_test" : "phpcs --standard=phpcs.xml -s -p --colors ./tests/",
"phpmd" : "phpmd ./ ansi cleancode, codesize, controversial, design, naming, unusedcode --exclude vendor"
}
"name": "jblond/php-diff",
"type": "library",
"description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
"license": "BSD-3-Clause",
"keywords": [
"php",
"diff"
],
"authors": [
{
"name": "Mario",
"email": "[email protected]"
},
{
"name": "Ferry Cools",
"email": "[email protected]"
},
{
"name": "Chris Boulton",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.2",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "8.*",
"squizlabs/php_codesniffer": "*",
"phpmd/phpmd": "2.*"
},
"autoload": {
"psr-4": {
"jblond\\": "lib/jblond"
}
},
"config": {
"classmap-authoritative": true
},
"scripts": {
"phpunit": "phpunit ./tests/",
"php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
"php_test": "phpcs --standard=phpcs.xml -s -p --colors ./tests/",
"phpmd": "phpmd ./ ansi cleancode,codesize,controversial,design,naming,unusedcode --exclude vendor"
}
}
47 changes: 29 additions & 18 deletions example/a.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>Hello World!</title>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>Hello World!</title>
</head>
<body>
<h1>This is demo content to show features of the php-diff package.</h1>
<h2>This line is removed from version2.</h2>
<h2>This line is the same for both versions.</h2>
<h2>This line has inline differences between both versions.</h2>
<h2>This line is the same for both versions.</h2>
<h2>This line also has inline differences between both versions.</h2>
<h2>This line is the same for both versions.</h2>

<h2>A heading we'll be removing</h2>
<pre>
构建具有中国特色的医学人才培养体系
</pre>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<pre>
另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
</pre>
<p>Do you know in Chinese, "金槍魚罐頭" means tuna can.</p>
</body>
<p>
It's also compatible with multibyte characters (like Chinese and emoji) as shown below:
另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
Do you know what "金槍魚罐頭" means in Chinese?
🍏🍎🙂
</p>

<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
<h2>This line is the same for both versions.</h2>
<h2>This line also has inline differences between both versions.</h2>
</body>
</html>
48 changes: 29 additions & 19 deletions example/b.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@

<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>Goodbye Cruel World!</title>
</head>
<body>
<p>Just a small amount of new text...</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>Hello You!</title>
</head>
<body>
<h1>This is demo content to show features of the php-diff package.</h1>
<h2>This line is the same for both versions.</h2>
<h2>This line has differences between both versions.</h2>
<h2>This line is the same for both versions.</h2>
<h2>This line also has InLine differences between both versions.</h2>
<h2>This line is the same for both versions.</h2>
<h2>This line is added to version2.</h2>

<p>
It's also compatible with multibyte characters (like Chinese and emoji) as shown below:
另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
Do you know what "魚の缶詰" means in Chinese?
🍎🍏🙂
</p>

<pre>
构建具有中国國的医学人才培养体系
</pre>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<pre>
另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
</pre>
<p>Do you know in Japanese, "魚の缶詰" means fish can.</p>
</body>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
<h2>This line is the same for both versions.</h2>
<h2>This line also has inline differences between both versions!</h2>
</body>
</html>
20 changes: 10 additions & 10 deletions example/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
$b = file_get_contents(dirname(__FILE__) . '/b.txt');

// Options for generating the diff.
$options = [
//'ignoreWhitespace' => true,
//'ignoreCase' => true,
//'context' => 2, /* Remove // to see text collapse in action */
$customOptions = [
'context' => 2,
'trimEqual' => false,
'ignoreWhitespace' => true,
'ignoreCase' => true,
];

// Initialize the diff class.
// \jblond\diff
$diff = new Diff($a, $b, $options);
// Choose one of the initializations.
$diff = new Diff($a, $b); // Initialize the diff class with default options.
//$diff = new Diff($a, $b, $customOptions); // Initialize the diff class with custom options.
?><!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -43,11 +44,10 @@
// Generate a side by side diff.
// \jblond\Diff\Renderer\Html
$renderer = new SideBySide([
'title_a' => 'Custom title for OLD version',
'title_b' => 'Custom title for NEW version',
'title1' => 'Custom title for version1',
'title2' => 'Custom title for version2',
]);
echo $diff->Render($renderer);

?>

<h2>HTML Inline Diff</h2>
Expand Down
Binary file added htmlInline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added htmlSideBySide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added htmlUnified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading