Skip to content

Commit aedefa8

Browse files
authored
Merge pull request #73 from JBlond/mergedRenderer
Add html merged renderer
2 parents 6e2ad47 + 3ccaa10 commit aedefa8

File tree

10 files changed

+462
-23
lines changed

10 files changed

+462
-23
lines changed

example/dark-theme.css

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
body {
22
background: #3A3B46;
3-
color: #F8F8F2;
3+
color: #F8F8F2;
44
font-family: Arial, serif;
55
font-size: 12px;
66
}
@@ -36,7 +36,7 @@ a, a:visited {
3636
.Differences tbody th {
3737
text-align: right;
3838
background: #AAAAAA;
39-
color: #272822;
39+
color: #272822;
4040
width: 4em;
4141
padding: 1px 2px;
4242
border-right: 1px solid #000000;
@@ -52,42 +52,43 @@ a, a:visited {
5252

5353
.Differences .Skipped {
5454
background: #F7F7F7;
55+
color: #000000;
56+
}
57+
58+
.Differences ins,
59+
.Differences del {
60+
text-decoration: none;
5561
}
5662

5763
/*
5864
* HTML Side by Side Diff
5965
*/
6066
.DifferencesSideBySide .ChangeInsert td.Left {
61-
background: green;
67+
background: #008000;
6268
}
6369

6470
.DifferencesSideBySide .ChangeInsert td.Right {
65-
background: green;
71+
background: #008000;
6672
}
6773

6874
.DifferencesSideBySide .ChangeDelete td.Left {
6975
background: #FF8888;
70-
color: #272822;
76+
color: #272822;
7177
}
7278

7379
.DifferencesSideBySide .ChangeDelete td.Right {
7480
background: #FFAAAA;
75-
color: #272822;
81+
color: #272822;
7682
}
7783

7884
.DifferencesSideBySide .ChangeReplace .Left {
7985
background: #FFEE99;
80-
color: #272822;
86+
color: #272822;
8187
}
8288

8389
.DifferencesSideBySide .ChangeReplace .Right {
8490
background: #FFDD88;
85-
color: #272822;
86-
}
87-
88-
.Differences ins,
89-
.Differences del {
90-
text-decoration: none;
91+
color: #272822;
9192
}
9293

9394
.DifferencesSideBySide .ChangeReplace ins,
@@ -106,7 +107,7 @@ a, a:visited {
106107
.DifferencesInline .ChangeReplace .Left,
107108
.DifferencesInline .ChangeDelete .Left {
108109
background: #FFDDDD;
109-
color: #272822;
110+
color: #272822;
110111
}
111112

112113
.DifferencesInline .ChangeReplace .Right,
@@ -115,12 +116,41 @@ a, a:visited {
115116
}
116117

117118
.DifferencesInline .ChangeReplace ins {
118-
background: green;
119+
background: #008000;
119120
}
120121

121122
.DifferencesInline .ChangeReplace del {
122123
background: #EE9999;
123-
color: #272822;
124+
color: #272822;
125+
}
126+
127+
/*
128+
* HTML Merged Diff
129+
*/
130+
.DifferencesMerged .ChangeReplace .Left,
131+
.DifferencesMerged .ChangeDelete {
132+
background: #FFDDDD;
133+
color: #272822;
134+
}
135+
136+
.DifferencesMerged .ChangeReplace .Right,
137+
.DifferencesMerged .ChangeInsert {
138+
background: #DDFFDD;
139+
color: #272822;
140+
}
141+
142+
.DifferencesMerged .ChangeReplace ins {
143+
background: #008000;
144+
color: #272822;
145+
}
146+
147+
.DifferencesMerged .ChangeReplace del {
148+
background: #EE9999;
149+
color: #272822;
150+
}
151+
152+
.DifferencesMerged th.ChangeDelete {
153+
background-image: linear-gradient(-45deg, #AAAAAA 0%, #EE9999 100%);
124154
}
125155

126156
/*
@@ -134,13 +164,13 @@ a, a:visited {
134164

135165
.DifferencesUnified .ChangeDelete .Left {
136166
background: #EE9999;
137-
color: #272822;
167+
color: #272822;
138168
}
139169

140170
/* Line modified in old and new */
141171
.DifferencesUnified .ChangeReplace {
142172
background: #FFEE99;
143-
color: #272822;
173+
color: #272822;
144174
display: table;
145175
}
146176

example/example.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use jblond\Diff;
44
use jblond\Diff\Renderer\Html\Inline;
5+
use jblond\Diff\Renderer\Html\Merged;
56
use jblond\Diff\Renderer\Html\SideBySide;
67
use jblond\Diff\Renderer\Html\Unified as HtmlUnified;
78
use jblond\Diff\Renderer\Text\Context;
@@ -23,7 +24,7 @@
2324
];
2425

2526
// Choose one of the initializations.
26-
$diff = new Diff($sampleA, $sampleB); // Initialize the diff class with default options.
27+
$diff = new Diff($sampleA, $sampleB); // Initialize the diff class with default options.
2728
//$diff = new Diff($sampleA, $sampleB, $diffOptions); // Initialize the diff class with custom options.
2829

2930
// Options for rendering the diff.
@@ -83,6 +84,13 @@ function changeCSS(cssFile, cssLinkIndex) {
8384
echo $diff->isIdentical() ? 'No differences found.' : $diff->Render($renderer);
8485
?>
8586

87+
<h2>HTML Merged Diff</h2>
88+
<?php
89+
// Generate an inline diff.
90+
$renderer = new Merged();
91+
echo $diff->isIdentical() ? 'No differences found.' : $diff->Render($renderer);
92+
?>
93+
8694
<h2>HTML Unified Diff</h2>
8795
<?php
8896
// Generate a unified diff.

example/styles.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
body {
22
background: #FFFFFF;
3+
color: #000000;
34
font-family: Arial, serif;
45
font-size: 12px;
56
}
@@ -106,6 +107,31 @@ pre {
106107
background: #EE9999;
107108
}
108109

110+
/*
111+
* HTML Merged Diff
112+
*/
113+
.DifferencesMerged .ChangeReplace .Left,
114+
.DifferencesMerged .ChangeDelete {
115+
background: #FFDDDD;
116+
}
117+
118+
.DifferencesMerged .ChangeReplace .Right,
119+
.DifferencesMerged .ChangeInsert {
120+
background: #DDFFDD;
121+
}
122+
123+
.DifferencesMerged .ChangeReplace ins {
124+
background: #99EE99;
125+
}
126+
127+
.DifferencesMerged .ChangeReplace del {
128+
background: #EE9999;
129+
}
130+
131+
.DifferencesMerged th.ChangeDelete {
132+
background-image: linear-gradient(-45deg, #CCCCCC 0%, #EE9999 100%);
133+
}
134+
109135
/*
110136
* HTML Unified Diff
111137
*/

lib/jblond/Diff/Renderer/Html/Inline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function generateLinesReplace(array $changes): string
233233
*
234234
* @param array $changes Contains the op-codes about the changes between two blocks of text.
235235
*
236-
* @return string Start of the diff view.
236+
* @return string Start of the block.
237237
*/
238238
public function generateBlockHeader(array $changes): string
239239
{

0 commit comments

Comments
 (0)