@@ -16,7 +16,7 @@ class HtmlDiff extends AbstractDiff
16
16
'dl ' => '[[REPLACE_DEFINITION_LIST]] ' ,
17
17
'table ' => '[[REPLACE_TABLE]] '
18
18
);
19
-
19
+
20
20
/**
21
21
* @param boolean $boolean
22
22
* @return HtmlDiff
@@ -46,7 +46,7 @@ public function build()
46
46
foreach ($ operations as $ item ) {
47
47
$ this ->performOperation ( $ item );
48
48
}
49
-
49
+
50
50
return $ this ->content ;
51
51
}
52
52
@@ -69,7 +69,7 @@ protected function replaceIsolatedDiffTags()
69
69
{
70
70
$ this ->oldIsolatedDiffTags = $ this ->createIsolatedDiffTagPlaceholders ($ this ->oldWords );
71
71
$ this ->newIsolatedDiffTags = $ this ->createIsolatedDiffTagPlaceholders ($ this ->newWords );
72
-
72
+
73
73
}
74
74
75
75
protected function createIsolatedDiffTagPlaceholders (&$ words )
@@ -191,25 +191,28 @@ protected function processDeleteOperation($operation, $cssClass)
191
191
$ this ->insertTag ( "del " , $ cssClass , $ text );
192
192
}
193
193
194
- protected function diffElements ($ oldText , $ newText )
194
+ protected function diffElements ($ oldText , $ newText, $ stripWrappingTags = true )
195
195
{
196
- $ pattern = '/(^<[^>]+>)|(<\/[^>]+>$)/i ' ;
197
- $ matches = array ();
198
196
$ wrapStart = '' ;
199
197
$ wrapEnd = '' ;
200
-
201
- if (preg_match_all ($ pattern , $ newText , $ matches )) {
202
- $ wrapStart = $ matches [0 ][0 ];
203
- $ wrapEnd = $ matches [0 ][1 ];
198
+
199
+ if ($ stripWrappingTags ) {
200
+ $ pattern = '/(^<[^>]+>)|(<\/[^>]+>$)/i ' ;
201
+ $ matches = array ();
202
+
203
+ if (preg_match_all ($ pattern , $ newText , $ matches )) {
204
+ $ wrapStart = isset ($ matches [0 ][0 ]) ? $ matches [0 ][0 ] : '' ;
205
+ $ wrapEnd = isset ($ matches [0 ][1 ]) ? $ matches [0 ][1 ] : '' ;
206
+ }
207
+ $ oldText = preg_replace ($ pattern , '' , $ oldText );
208
+ $ newText = preg_replace ($ pattern , '' , $ newText );
204
209
}
205
- $ oldText = preg_replace ($ pattern , '' , $ oldText );
206
- $ newText = preg_replace ($ pattern , '' , $ newText );
207
210
208
211
$ diff = new HtmlDiff ($ oldText , $ newText , $ this ->encoding , $ this ->specialCaseTags , $ this ->groupDiffs );
209
212
210
213
return $ wrapStart . $ diff ->build () . $ wrapEnd ;
211
214
}
212
-
215
+
213
216
protected function diffList ($ oldText , $ newText )
214
217
{
215
218
$ diff = new ListDiff ($ oldText , $ newText , $ this ->encoding , $ this ->specialCaseTags , $ this ->groupDiffs );
@@ -220,13 +223,13 @@ protected function processEqualOperation($operation)
220
223
{
221
224
$ result = array ();
222
225
foreach ($ this ->newWords as $ pos => $ s ) {
223
-
226
+
224
227
if ($ pos >= $ operation ->startInNew && $ pos < $ operation ->endInNew ) {
225
228
if (in_array ($ s , $ this ->isolatedDiffTags ) && isset ($ this ->newIsolatedDiffTags [$ pos ])) {
226
-
229
+
227
230
$ oldText = implode ("" , $ this ->findIsolatedDiffTagsInOld ($ operation , $ pos ));
228
231
$ newText = implode ("" , $ this ->newIsolatedDiffTags [$ pos ]);
229
-
232
+
230
233
if ($ this ->isListPlaceholder ($ s )) {
231
234
$ result [] = $ this ->diffList ($ oldText , $ newText );
232
235
} else {
@@ -239,7 +242,7 @@ protected function processEqualOperation($operation)
239
242
}
240
243
$ this ->content .= implode ( "" , $ result );
241
244
}
242
-
245
+
243
246
protected function isListPlaceholder ($ text )
244
247
{
245
248
if (in_array ($ text , array (
@@ -249,7 +252,7 @@ protected function isListPlaceholder($text)
249
252
))) {
250
253
return true ;
251
254
}
252
-
255
+
253
256
return false ;
254
257
}
255
258
0 commit comments