5
5
* PHP version 5
6
6
*
7
7
* Copyright (c) 2009 Chris Boulton <[email protected] >
8
- *
8
+ *
9
9
* All rights reserved.
10
- *
11
- * Redistribution and use in source and binary forms, with or without
10
+ *
11
+ * Redistribution and use in source and binary forms, with or without
12
12
* modification, are permitted provided that the following conditions are met:
13
13
*
14
14
* - Redistributions of source code must retain the above copyright notice,
15
15
* this list of conditions and the following disclaimer.
16
16
* - Redistributions in binary form must reproduce the above copyright notice,
17
17
* this list of conditions and the following disclaimer in the documentation
18
18
* and/or other materials provided with the distribution.
19
- * - Neither the name of the Chris Boulton nor the names of its contributors
20
- * may be used to endorse or promote products derived from this software
19
+ * - Neither the name of the Chris Boulton nor the names of its contributors
20
+ * may be used to endorse or promote products derived from this software
21
21
* without specific prior written permission.
22
22
*
23
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
33
* POSSIBILITY OF SUCH DAMAGE.
34
34
*
35
35
* @package DiffLib
40
40
* @link http://github.com/chrisboulton/php-diff
41
41
*/
42
42
43
- require_once dirname (__FILE__ ). '/Array.php ' ;
43
+ require_once dirname (__FILE__ ) . '/Array.php ' ;
44
44
45
45
class Diff_Renderer_Html_Inline extends Diff_Renderer_Html_Array
46
46
{
47
- /**
48
- * Render a and return diff with changes between the two sequences
49
- * displayed inline (under each other)
50
- *
51
- * @return string The generated inline diff.
52
- */
53
- public function render ()
54
- {
55
- $ changes = parent ::render ();
56
- $ html = '' ;
57
- if (empty ($ changes )) {
58
- return $ html ;
59
- }
60
47
61
- $ html .= '<table class="Differences DifferencesInline"> ' ;
62
- $ html .= '<thead> ' ;
63
- $ html .= '<tr> ' ;
64
- $ html .= '<th>Old</th> ' ;
65
- $ html .= '<th>New</th> ' ;
66
- $ html .= '<th>Differences</th> ' ;
67
- $ html .= '</tr> ' ;
68
- $ html .= '</thead> ' ;
69
- foreach ($ changes as $ i => $ blocks ) {
70
- // If this is a separate block, we're condensing code so output ...,
71
- // indicating a significant portion of the code has been collapsed as
72
- // it is the same
73
- if ($ i > 0 ) {
74
- $ html .= '<tbody class="Skipped"> ' ;
75
- $ html .= '<th>…</th> ' ;
76
- $ html .= '<th>…</th> ' ;
77
- $ html .= '<td> </td> ' ;
78
- $ html .= '</tbody> ' ;
79
- }
48
+ /**
49
+ * Render a and return diff with changes between the two sequences
50
+ * displayed inline (under each other)
51
+ *
52
+ * @return string The generated inline diff.
53
+ */
54
+ public function render ()
55
+ {
56
+ $ changes = parent ::render ();
57
+ $ html = '' ;
58
+ if (empty ($ changes )) {
59
+ return $ html ;
60
+ }
61
+
62
+ foreach ($ changes as $ i => $ blocks ) {
63
+ // If this is a separate block, we're condensing code so output ...,
64
+ // indicating a significant portion of the code has been collapsed as
65
+ // it is the same
66
+ if ($ i > 0 ) {
67
+ $ html .= '<div class="diff diff-empty"></div> ' ;
68
+ }
69
+
70
+ foreach ($ blocks as $ change ) {
80
71
81
- foreach ($ blocks as $ change ) {
82
- $ html .= '<tbody class="Change ' .ucfirst ($ change ['tag ' ]).'"> ' ;
83
- // Equal changes should be shown on both sides of the diff
84
- if ($ change ['tag ' ] == 'equal ' ) {
85
- foreach ($ change ['base ' ]['lines ' ] as $ no => $ line ) {
86
- $ fromLine = $ change ['base ' ]['offset ' ] + $ no + 1 ;
87
- $ toLine = $ change ['changed ' ]['offset ' ] + $ no + 1 ;
88
- $ html .= '<tr> ' ;
89
- $ html .= '<th> ' .$ fromLine .'</th> ' ;
90
- $ html .= '<th> ' .$ toLine .'</th> ' ;
91
- $ html .= '<td class="Left"> ' .$ line .'</td> ' ;
92
- $ html .= '</tr> ' ;
93
- }
94
- }
95
- // Added lines only on the right side
96
- else if ($ change ['tag ' ] == 'insert ' ) {
97
- foreach ($ change ['changed ' ]['lines ' ] as $ no => $ line ) {
98
- $ toLine = $ change ['changed ' ]['offset ' ] + $ no + 1 ;
99
- $ html .= '<tr> ' ;
100
- $ html .= '<th> </th> ' ;
101
- $ html .= '<th> ' .$ toLine .'</th> ' ;
102
- $ html .= '<td class="Right"><ins> ' .$ line .'</ins> </td> ' ;
103
- $ html .= '</tr> ' ;
104
- }
105
- }
106
- // Show deleted lines only on the left side
107
- else if ($ change ['tag ' ] == 'delete ' ) {
108
- foreach ($ change ['base ' ]['lines ' ] as $ no => $ line ) {
109
- $ fromLine = $ change ['base ' ]['offset ' ] + $ no + 1 ;
110
- $ html .= '<tr> ' ;
111
- $ html .= '<th> ' .$ fromLine .'</th> ' ;
112
- $ html .= '<th> </th> ' ;
113
- $ html .= '<td class="Left"><del> ' .$ line .'</del> </td> ' ;
114
- $ html .= '</tr> ' ;
115
- }
116
- }
117
- // Show modified lines on both sides
118
- else if ($ change ['tag ' ] == 'replace ' ) {
119
- foreach ($ change ['base ' ]['lines ' ] as $ no => $ line ) {
120
- $ fromLine = $ change ['base ' ]['offset ' ] + $ no + 1 ;
121
- $ html .= '<tr> ' ;
122
- $ html .= '<th> ' .$ fromLine .'</th> ' ;
123
- $ html .= '<th> </th> ' ;
124
- $ html .= '<td class="Left"><span> ' .$ line .'</span></td> ' ;
125
- $ html .= '</tr> ' ;
126
- }
72
+ // Equal changes should be shown on both sides of the diff
73
+ if ($ change ['tag ' ] == 'equal ' ) {
74
+ foreach ($ change ['base ' ]['lines ' ] as $ no => $ line ) {
75
+ $ html .= '<div class="diff diff-equal"> '
76
+ . $ line
77
+ . '</div> ' ;
78
+ }
79
+ } // Added lines only on the right side
80
+ else if ($ change ['tag ' ] == 'insert ' ) {
81
+ foreach ($ change ['changed ' ]['lines ' ] as $ no => $ line ) {
82
+ $ html .= '<div class="diff diff-added" style="background-color: #DDFADE;"> '
83
+ . '<ins style="background: #9e9; text-decoration: none !important;"> '
84
+ . $ line
85
+ . '</ins> </div> ' ;
86
+ }
87
+ } // Show deleted lines only on the left side
88
+ else if ($ change ['tag ' ] == 'delete ' ) {
89
+ foreach ($ change ['base ' ]['lines ' ] as $ no => $ line ) {
90
+ $ html .= '<div class="diff diff-removed" style="background-color: #FFE7E7;"> '
91
+ . '<del style="background: #e99; text-decoration: line-through;"> '
92
+ . $ line
93
+ . '</del> </div> ' ;
94
+ }
95
+ } // Show modified lines on both sides
96
+ else if ($ change ['tag ' ] == 'replace ' ) {
97
+ foreach ($ change ['base ' ]['lines ' ] as $ no => $ line ) {
98
+ $ html .= '<div class="diff diff-removed" style="background-color: #FFE7E7;"><span> '
99
+ . $ line
100
+ . '</span></div> ' ;
101
+ }
127
102
128
- foreach ($ change ['changed ' ]['lines ' ] as $ no => $ line ) {
129
- $ toLine = $ change ['changed ' ]['offset ' ] + $ no + 1 ;
130
- $ html .= '<tr> ' ;
131
- $ html .= '<th> ' .$ toLine .'</th> ' ;
132
- $ html .= '<th> </th> ' ;
133
- $ html .= '<td class="Right"><span> ' .$ line .'</span></td> ' ;
134
- $ html .= '</tr> ' ;
135
- }
136
- }
137
- $ html .= '</tbody> ' ;
138
- }
139
- }
140
- $ html .= '</table> ' ;
141
- return $ html ;
142
- }
103
+ foreach ($ change ['changed ' ]['lines ' ] as $ no => $ line ) {
104
+ $ html .= '<div class="diff diff-added" style="background-color: #DDFADE;"><span> '
105
+ . $ line
106
+ . '</span></div> ' ;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ return $ html ;
112
+ }
143
113
}
0 commit comments