Skip to content

Commit ec0918b

Browse files
committed
Fix visibility of removed lines
* Lines which are removed from version 2 where indicated by an asterisk in front of the line number. This was easy to overlook. The indicator is a class now so it can by styled by css. * Block bodies of removed lines where still rendered even though they had no content.
1 parent cef85b5 commit ec0918b

File tree

4 files changed

+76
-63
lines changed

4 files changed

+76
-63
lines changed

example/dark-theme.css

Lines changed: 19 additions & 15 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,7 +52,7 @@ a, a:visited {
5252

5353
.Differences .Skipped {
5454
background: #F7F7F7;
55-
color: #000000;
55+
color: #000000;
5656
}
5757

5858
.Differences ins,
@@ -73,22 +73,22 @@ a, a:visited {
7373

7474
.DifferencesSideBySide .ChangeDelete td.Left {
7575
background: #FF8888;
76-
color: #272822;
76+
color: #272822;
7777
}
7878

7979
.DifferencesSideBySide .ChangeDelete td.Right {
8080
background: #FFAAAA;
81-
color: #272822;
81+
color: #272822;
8282
}
8383

8484
.DifferencesSideBySide .ChangeReplace .Left {
8585
background: #FFEE99;
86-
color: #272822;
86+
color: #272822;
8787
}
8888

8989
.DifferencesSideBySide .ChangeReplace .Right {
9090
background: #FFDD88;
91-
color: #272822;
91+
color: #272822;
9292
}
9393

9494
.DifferencesSideBySide .ChangeReplace ins,
@@ -107,7 +107,7 @@ a, a:visited {
107107
.DifferencesInline .ChangeReplace .Left,
108108
.DifferencesInline .ChangeDelete .Left {
109109
background: #FFDDDD;
110-
color: #272822;
110+
color: #272822;
111111
}
112112

113113
.DifferencesInline .ChangeReplace .Right,
@@ -121,7 +121,7 @@ a, a:visited {
121121

122122
.DifferencesInline .ChangeReplace del {
123123
background: #EE9999;
124-
color: #272822;
124+
color: #272822;
125125
}
126126

127127
/*
@@ -130,23 +130,27 @@ a, a:visited {
130130
.DifferencesMerged .ChangeReplace .Left,
131131
.DifferencesMerged .ChangeDelete {
132132
background: #FFDDDD;
133-
color: #272822;
133+
color: #272822;
134134
}
135135

136136
.DifferencesMerged .ChangeReplace .Right,
137137
.DifferencesMerged .ChangeInsert {
138138
background: #DDFFDD;
139-
color: #272822;
139+
color: #272822;
140140
}
141141

142142
.DifferencesMerged .ChangeReplace ins {
143143
background: #008000;
144-
color: #272822;
144+
color: #272822;
145145
}
146146

147147
.DifferencesMerged .ChangeReplace del {
148148
background: #EE9999;
149-
color: #272822;
149+
color: #272822;
150+
}
151+
152+
.DifferencesMerged th.ChangeDelete {
153+
background-image: linear-gradient(-45deg, #AAAAAA 0%, #EE9999 100%);
150154
}
151155

152156
/*
@@ -160,13 +164,13 @@ a, a:visited {
160164

161165
.DifferencesUnified .ChangeDelete .Left {
162166
background: #EE9999;
163-
color: #272822;
167+
color: #272822;
164168
}
165169

166170
/* Line modified in old and new */
167171
.DifferencesUnified .ChangeReplace {
168172
background: #FFEE99;
169-
color: #272822;
173+
color: #272822;
170174
display: table;
171175
}
172176

example/styles.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
body {
22
background: #FFFFFF;
3-
color: #000000;
3+
color: #000000;
44
font-family: Arial, serif;
55
font-size: 12px;
66
}
@@ -128,6 +128,10 @@ pre {
128128
background: #EE9999;
129129
}
130130

131+
.DifferencesMerged th.ChangeDelete {
132+
background-image: linear-gradient(-45deg, #CCCCCC 0%, #EE9999 100%);
133+
}
134+
131135
/*
132136
* HTML Unified Diff
133137
*/

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,26 @@ public function generateDiffHeader(): string
8787
*/
8888
public function generateBlockHeader(array $changes): string
8989
{
90-
return '<tbody class="Change' . ucfirst($changes['tag']) . '">';
90+
return $changes['tag'] != 'delete' ? '<tbody class="Change' . ucfirst($changes['tag']) . '">' : '';
9191
}
9292

9393
/**
9494
* @inheritDoc
9595
*/
9696
public function generateSkippedLines(): string
9797
{
98-
$marker = '&hellip;';
98+
$marker = '&hellip;';
99+
$headerClass = '';
100+
99101
if ($this->lastDeleted !== null) {
100-
$marker = "*$marker";
102+
$headerClass = 'ChangeDelete';
101103
}
102104

103105
$this->lastDeleted = null;
104106

105107
return <<<HTML
106108
<tr>
107-
<th title="{$this->lastDeleted}">$marker</th>
109+
<th class="$headerClass" title="{$this->lastDeleted}">$marker</th>
108110
<td class="Skipped">&hellip;</td>
109111
</tr>
110112
HTML;
@@ -115,17 +117,18 @@ public function generateSkippedLines(): string
115117
*/
116118
public function generateLinesEqual(array $changes): string
117119
{
118-
$html = '';
120+
$html = '';
121+
$headerClass = '';
119122

120123
foreach ($changes['base']['lines'] as $lineNo => $line) {
121124
$fromLine = $changes['base']['offset'] + $lineNo + 1 + $this->lineOffset;
122125
if (!$lineNo && $this->lastDeleted !== null) {
123-
$fromLine = "*$fromLine";
126+
$headerClass = 'ChangeDelete';
124127
}
125128

126129
$html .= <<<HTML
127130
<tr>
128-
<th title="{$this->lastDeleted}">$fromLine</th>
131+
<th class="$headerClass" title="{$this->lastDeleted}">$fromLine</th>
129132
<td>$line</td>
130133
</tr>
131134
HTML;
@@ -140,18 +143,19 @@ public function generateLinesEqual(array $changes): string
140143
*/
141144
public function generateLinesInsert(array $changes): string
142145
{
143-
$html = '';
146+
$html = '';
147+
$headerClass = '';
144148

145149
foreach ($changes['changed']['lines'] as $lineNo => $line) {
146150
$this->lineOffset++;
147151
$toLine = $changes['base']['offset'] + $this->lineOffset;
148152
if (!$lineNo && $this->lastDeleted !== null) {
149-
$toLine = "*$toLine";
153+
$headerClass = 'ChangeDelete';
150154
}
151155

152156
$html .= <<<HTML
153157
<tr>
154-
<th title="{$this->lastDeleted}">$toLine</th>
158+
<th class="$headerClass" title="{$this->lastDeleted}">$toLine</th>
155159
<td><ins>$line</ins></td>
156160
</tr>
157161
HTML;
@@ -190,12 +194,13 @@ public function generateLinesDelete(array $changes): string
190194
*/
191195
public function generateLinesReplace(array $changes): string
192196
{
193-
$html = '';
197+
$html = '';
198+
$headerClass = '';
194199

195200
foreach ($changes['base']['lines'] as $lineNo => $line) {
196201
$fromLine = $changes['base']['offset'] + $lineNo + 1 + $this->lineOffset;
197202
if (!$lineNo && $this->lastDeleted !== null) {
198-
$fromLine = "*$fromLine";
203+
$headerClass = 'ChangeDelete';
199204
}
200205

201206
// Capture added parts.
@@ -217,7 +222,7 @@ function ($removedParts) use ($addedParts) {
217222

218223
$html .= <<<HTML
219224
<tr>
220-
<th title="{$this->lastDeleted}">$fromLine</th>
225+
<th class="$headerClass" title="{$this->lastDeleted}">$fromLine</th>
221226
<td>$line</td>
222227
</tr>
223228
HTML;

tests/resources/htmlMerged.txt

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,101 +4,101 @@
44
<th colspan="2">Merge of Version1 &amp; Version2</th>
55
</tr>
66
</thead><tbody class="ChangeEqual"><tr>
7-
<th title="">1</th>
7+
<th class="" title="">1</th>
88
<td>&lt;html&gt;</td>
99
</tr><tr>
10-
<th title="">2</th>
10+
<th class="" title="">2</th>
1111
<td>&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;</td>
1212
</tr><tr>
13-
<th title="">3</th>
13+
<th class="" title="">3</th>
1414
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta http-equiv="Content-type" content="text/html; charset=utf-8"/&gt;</td>
1515
</tr></tbody><tbody class="ChangeReplace"><tr>
16-
<th title="">4</th>
16+
<th class="" title="">4</th>
1717
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Hello <del>World</del><ins>You</ins>!&lt;/title&gt;</td>
1818
</tr></tbody><tbody class="ChangeEqual"><tr>
19-
<th title="">5</th>
19+
<th class="" title="">5</th>
2020
<td>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/head&gt;</td>
2121
</tr><tr>
22-
<th title="">6</th>
22+
<th class="" title="">6</th>
2323
<td>&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&gt;</td>
2424
</tr><tr>
25-
<th title="">7</th>
25+
<th class="" title="">7</th>
2626
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;This is demo content to show features of the php-diff package.&lt;/h1&gt;</td>
27-
</tr></tbody><tbody class="ChangeDelete"></tbody><tbody class="ChangeEqual"><tr>
28-
<th title="Lines deleted at Version2:
27+
</tr></tbody></tbody><tbody class="ChangeEqual"><tr>
28+
<th class="ChangeDelete" title="Lines deleted at Version2:
2929
8: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is removed from version2.&lt;/h2&gt;
30-
">*8</th>
30+
">8</th>
3131
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is the same for both versions.&lt;/h2&gt;</td>
3232
</tr></tbody><tbody class="ChangeReplace"><tr>
33-
<th title="">9</th>
33+
<th class="" title="">9</th>
3434
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line has <del>inline </del><ins></ins>differences between both versions.&lt;/h2&gt;</td>
3535
</tr></tbody><tbody class="ChangeEqual"><tr>
36-
<th title="">10</th>
36+
<th class="" title="">10</th>
3737
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is the same for both versions.&lt;/h2&gt;</td>
3838
</tr></tbody><tbody class="ChangeReplace"><tr>
39-
<th title="">11</th>
39+
<th class="" title="">11</th>
4040
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line also has <del>inl</del><ins>InL</ins>ine differences between both versions.&lt;/h2&gt;</td>
4141
</tr></tbody><tbody class="ChangeEqual"><tr>
42-
<th title="">12</th>
42+
<th class="" title="">12</th>
4343
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is the same for both versions.&lt;/h2&gt;</td>
4444
</tr></tbody><tbody class="ChangeInsert"><tr>
45-
<th title="">13</th>
45+
<th class="" title="">13</th>
4646
<td><ins>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is added to version2.&lt;/h2&gt;</ins></td>
4747
</tr></tbody><tbody class="ChangeEqual"><tr>
48-
<th title="">14</th>
48+
<th class="" title="">14</th>
4949
<td></td>
5050
</tr><tr>
51-
<th title="">15</th>
51+
<th class="" title="">15</th>
5252
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;</td>
5353
</tr><tr>
54-
<th title="">16</th>
54+
<th class="" title="">16</th>
5555
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It's also compatible with multibyte characters (like Chinese and emoji) as shown below:</td>
5656
</tr></tbody><tbody class="ChangeReplace"><tr>
57-
<th title="">17</th>
57+
<th class="" title="">17</th>
5858
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;另外我覺得那個評<del>價</del><ins>鑑</ins>的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”</td>
5959
</tr><tr>
60-
<th title="">18</th>
60+
<th class="" title="">18</th>
6161
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Do you know what "<del>金槍魚罐頭</del><ins>魚の缶詰</ins>" means in Chinese?</td>
6262
</tr><tr>
63-
<th title="">19</th>
63+
<th class="" title="">19</th>
6464
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<del>🍏🍎</del><ins>🍎🍏</ins>🙂</td>
6565
</tr></tbody><tbody class="ChangeEqual"><tr>
66-
<th title="">20</th>
66+
<th class="" title="">20</th>
6767
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/p&gt;</td>
6868
</tr><tr>
69-
<th title="">21</th>
69+
<th class="" title="">21</th>
7070
<td></td>
7171
</tr><tr>
72-
<th title="">22</th>
72+
<th class="" title="">22</th>
7373
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.&lt;/p&gt;</td>
7474
</tr></tbody><tr>
75-
<th title="">&hellip;</th>
75+
<th class="" title="">&hellip;</th>
7676
<td class="Skipped">&hellip;</td>
7777
</tr><tbody class="ChangeEqual"><tr>
78-
<th title="">25</th>
78+
<th class="" title="">25</th>
7979
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.&lt;/p&gt;</td>
8080
</tr><tr>
81-
<th title="">26</th>
81+
<th class="" title="">26</th>
8282
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.&lt;/p&gt;</td>
8383
</tr><tr>
84-
<th title="">27</th>
84+
<th class="" title="">27</th>
8585
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.&lt;/p&gt;</td>
8686
</tr></tbody><tbody class="ChangeReplace"><tr>
87-
<th title="">28</th>
87+
<th class="" title="">28</th>
8888
<td><del>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</del><ins>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</ins>&lt;h2&gt;This line also has inline differences between both versions. It's the whitespace in front.&lt;/h2&gt;</td>
8989
</tr></tbody><tbody class="ChangeEqual"><tr>
90-
<th title="">29</th>
90+
<th class="" title="">29</th>
9191
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line is the same for both versions.&lt;/h2&gt;</td>
9292
</tr></tbody><tbody class="ChangeReplace"><tr>
93-
<th title="">30</th>
93+
<th class="" title="">30</th>
9494
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;This line also has inline differences between both versions<del>.</del><ins>!</ins>&lt;/h2&gt;</td>
9595
</tr></tbody><tbody class="ChangeEqual"><tr>
96-
<th title="">31</th>
96+
<th class="" title="">31</th>
9797
<td>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;</td>
9898
</tr><tr>
99-
<th title="">32</th>
99+
<th class="" title="">32</th>
100100
<td>&lt;/html&gt;</td>
101101
</tr><tr>
102-
<th title="">33</th>
102+
<th class="" title="">33</th>
103103
<td></td>
104104
</tr></tbody></table>

0 commit comments

Comments
 (0)