Skip to content

Commit 33ba153

Browse files
committed
Merge branch 'NewExampleTexts' into DigiLive
2 parents b5e2cb0 + cd653c2 commit 33ba153

19 files changed

+523
-280
lines changed

README.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66

77
## Introduction
88

9-
A comprehensive library for generating differences between
10-
two hashable objects (strings or arrays). Generated differences can be
11-
rendered in all of the standard formats including:
9+
A comprehensive library for generating differences between two hashable objects (strings or arrays).
10+
Generated differences can be rendered in all of the standard formats including:
1211
* Unified
1312
* Context
1413
* Inline HTML
1514
* Side by Side HTML
1615
* Unified HTML
1716

18-
The logic behind the core of the diff engine (ie, the sequence matcher)
19-
is primarily based on the Python difflib package. The reason for doing
20-
so is primarily because of its high degree of accuracy.
21-
17+
The logic behind the core of the diff engine (ie, the sequence matcher) is primarily based on the Python difflib
18+
package. The reason for doing so is primarily because of its high degree of accuracy.
2219

2320
## Install
2421

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

4340
// Options for generating the diff.
4441
$options = [
45-
//'ignoreWhitespace' => true,
46-
//'ignoreCase' => true,
42+
'ignoreWhitespace' => true,
43+
'ignoreCase' => true,
44+
'context' => 2,
4745
];
4846

4947
// Initialize the diff class.
50-
$diff = new \jblond\Diff($a, $b, $options);
48+
$diff = new \jblond\Diff($a, $b /*, $options */);
5149

5250
// Choose Renderer.
5351
$renderer = new \jblond\Diff\Renderer\Html\SideBySide([
54-
'title_a' => 'Custom title for OLD version',
55-
'title_b' => 'Custom title for NEW version',
52+
'title1' => 'Custom title for OLD version',
53+
'title2' => 'Custom title for NEW version',
5654
]);
5755

5856
// Show it.
5957
echo $diff->Render($renderer);
6058
```
6159

6260
### Example Output
63-
A quick usage example can be found in the example/ directory and under
64-
example.php.
65-
66-
![Example Image](readme.png "Example")
61+
A quick usage example can be found in the `example/` directory and under example.php.
6762

68-
![Example 2 Image](readme2.png "Example2")
63+
![HTML Side By Side Example](htmlSideBySide.png "HTML Side By Side Example")
64+
![HTML Inline Example](htmlInline.png "HTML Inline Example")
65+
![HTML Unified Example](htmlUnified.png "HTML Unified Example")
66+
![Text Unified Example](textUnified.png "Text Unified Example")
67+
![Text Context Example](textContext.png "Text Context Example")
6968

7069
## Requirements
7170

7271
* PHP 7.2 or greater
73-
* PHP Multibyte String
72+
* PHP Multibyte String
7473

7574
## Merge files using jQuery
7675

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

8079
## Todo
8180

example/a.txt

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
<html>
2-
<head>
3-
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4-
<title>Hello World!</title>
5-
</head>
6-
<body>
7-
<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>
2+
<head>
3+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4+
<title>Hello World!</title>
5+
</head>
6+
<body>
7+
<h1>This is demo content to show features of the php-diff package.</h1>
8+
<h2>This line is removed from version2.</h2>
9+
<h2>This line is the same for both versions.</h2>
10+
<h2>This line has inline differences between both versions.</h2>
11+
<h2>This line is the same for both versions.</h2>
12+
<h2>This line also has inline differences between both versions.</h2>
13+
<h2>This line is the same for both versions.</h2>
814

9-
<h2>A heading we'll be removing</h2>
10-
<pre>
11-
构建具有中国特色的医学人才培养体系
12-
</pre>
13-
<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>
14-
<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>
15-
<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>
16-
<pre>
17-
另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
18-
</pre>
19-
<p>Do you know in Chinese, "金槍魚罐頭" means tuna can.</p>
20-
</body>
15+
<p>
16+
It's also compatible with multibyte characters (such as emoji) as shown below:
17+
Do you know what "金槍魚罐頭" means in Chinese?
18+
🍏🍎🙂
19+
</p>
20+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
21+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
22+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
23+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
24+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
25+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
26+
<h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
27+
<h2>This line is the same for both versions.</h2>
28+
<h2>This line also has inline differences between both versions.</h2>
29+
</body>
2130
</html>

example/b.txt

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1-
21
<html>
3-
<head>
4-
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5-
<title>Goodbye Cruel World!</title>
6-
</head>
7-
<body>
8-
<p>Just a small amount of new text...</p>
9-
<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>
2+
<head>
3+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4+
<title>Hello You!</title>
5+
</head>
6+
<body>
7+
<h1>This is demo content to show features of the php-diff package.</h1>
8+
<h2>This line is the same for both versions.</h2>
9+
<h2>This line has differences between both versions.</h2>
10+
<h2>This line is the same for both versions.</h2>
11+
<h2>This line also has InLine differences between both versions.</h2>
12+
<h2>This line is the same for both versions.</h2>
13+
<h2>This line is added to version2.</h2>
1014

11-
<pre>
12-
构建具有中国國的医学人才培养体系
13-
</pre>
14-
<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>
15-
<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>
16-
<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>
17-
<pre>
18-
另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
19-
</pre>
20-
<p>Do you know in Japanese, "魚の缶詰" means fish can.</p>
21-
</body>
15+
<p>
16+
It's also compatible with multibyte characters (such as emoji) as shown below:
17+
Do you know what "魚の缶詰" means in Chinese?
18+
🍎🍏🙂
19+
</p>
20+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
21+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
22+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
23+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
24+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
25+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
26+
<h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
27+
<h2>This line is the same for both versions.</h2>
28+
<h2>This line also has inline differences between both versions!</h2>
29+
</body>
2230
</html>

htmlInline.png

51.5 KB
Loading

htmlSideBySide.png

39.5 KB
Loading

htmlUnified.png

44 KB
Loading

readme.png

-102 KB
Binary file not shown.

readme2.png

-51.4 KB
Binary file not shown.

tests/Diff/Renderer/Html/HtmlRenderersTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
*/
2020
class HtmlRendererTest extends TestCase
2121
{
22+
/**
23+
* @var bool Store the renderer's output in a file, when set to true.
24+
*/
25+
private $genOutputFiles = false;
2226

2327
/**
2428
* Constructor.
@@ -29,6 +33,7 @@ class HtmlRendererTest extends TestCase
2933
*/
3034
public function __construct($name = null, array $data = [], $dataName = '')
3135
{
36+
//$this->genOutputFiles = true;
3237
parent::__construct($name, $data, $dataName);
3338
}
3439

@@ -41,7 +46,9 @@ public function testSideBySide()
4146

4247
$renderer = new SideBySide();
4348
$result = $diff->render($renderer);
44-
//file_put_contents('htmlSideBySide.txt', $result);
49+
if ($this->genOutputFiles) {
50+
file_put_contents('htmlSideBySide.txt', $result);
51+
}
4552

4653
$this->assertStringEqualsFile('tests/resources/htmlSideBySide.txt', $result);
4754
}
@@ -55,7 +62,9 @@ public function testInline()
5562

5663
$renderer = new Inline();
5764
$result = $diff->render($renderer);
58-
//file_put_contents('htmlInline.txt', $result);
65+
if ($this->genOutputFiles) {
66+
file_put_contents('htmlInline.txt', $result);
67+
}
5968

6069
$this->assertStringEqualsFile('tests/resources/htmlInline.txt', $result);
6170
}
@@ -69,7 +78,9 @@ public function testUnified()
6978

7079
$renderer = new Unified();
7180
$result = $diff->render($renderer);
72-
//file_put_contents('htmlUnified.txt', $result);
81+
if ($this->genOutputFiles) {
82+
file_put_contents('htmlUnified.txt', $result);
83+
}
7384

7485
$this->assertStringEqualsFile('tests/resources/htmlUnified.txt', $result);
7586
}

tests/Diff/Renderer/Text/TextRenderersTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
*/
1919
class TextRendererTest extends TestCase
2020
{
21+
/**
22+
* @var bool Store the renderer's output in a file, when set to true.
23+
*/
24+
private $genOutputFiles = false;
2125

2226
/**
2327
* Constructor.
@@ -28,6 +32,7 @@ class TextRendererTest extends TestCase
2832
*/
2933
public function __construct($name = null, array $data = [], $dataName = '')
3034
{
35+
//$this->genOutputFiles = true;
3136
parent::__construct($name, $data, $dataName);
3237
}
3338

@@ -40,7 +45,9 @@ public function testContext()
4045

4146
$renderer = new Context();
4247
$result = $diff->render($renderer);
43-
//file_put_contents('textContext.txt', $result);
48+
if ($this->genOutputFiles) {
49+
file_put_contents('textContext.txt', $result);
50+
}
4451

4552
$this->assertStringEqualsFile('tests/resources/textContext.txt', $result);
4653
}
@@ -54,7 +61,9 @@ public function testUnified()
5461

5562
$renderer = new Unified();
5663
$result = $diff->render($renderer);
57-
//file_put_contents('textUnified.txt', $result);
64+
if ($this->genOutputFiles) {
65+
file_put_contents('textUnified.txt', $result);
66+
}
5867

5968
$this->assertStringEqualsFile('tests/resources/textUnified.txt', $result);
6069
}

tests/resources/a.txt

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
<html>
2-
<head>
3-
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4-
<title>Hello World!</title>
5-
</head>
6-
<body>
7-
<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>
2+
<head>
3+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
4+
<title>Hello World!</title>
5+
</head>
6+
<body>
7+
<h1>This is demo content to show features of the php-diff package.</h1>
8+
<h2>This line is removed from version2.</h2>
9+
<h2>This line is the same for both versions.</h2>
10+
<h2>This line has inline differences between both versions.</h2>
11+
<h2>This line is the same for both versions.</h2>
12+
<h2>This line also has inline differences between both versions.</h2>
13+
<h2>This line is the same for both versions.</h2>
814

9-
<h2>A heading we'll be removing</h2>
10-
<pre>
11-
构建具有中国特色的医学人才培养体系
12-
</pre>
13-
<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>
14-
<pre>
15-
另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
16-
</pre>
17-
<p>Do you know in Chinese, "金槍魚罐頭" means tuna can.</p>
18-
</body>
15+
<p>
16+
It's also compatible with multibyte characters (such as emoji) as shown below:
17+
Do you know what "金槍魚罐頭" means in Chinese?
18+
🍏🍎🙂
19+
</p>
20+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
21+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
22+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
23+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
24+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
25+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
26+
<h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
27+
<h2>This line is the same for both versions.</h2>
28+
<h2>This line also has inline differences between both versions.</h2>
29+
</body>
1930
</html>

0 commit comments

Comments
 (0)