@@ -16,7 +16,7 @@ class HtmlDiff extends AbstractDiff
1616 'dl ' => '[[REPLACE_DEFINITION_LIST]] ' ,
1717 'table ' => '[[REPLACE_TABLE]] '
1818 );
19-
19+
2020 /**
2121 * @param boolean $boolean
2222 * @return HtmlDiff
@@ -46,7 +46,7 @@ public function build()
4646 foreach ($ operations as $ item ) {
4747 $ this ->performOperation ( $ item );
4848 }
49-
49+
5050 return $ this ->content ;
5151 }
5252
@@ -69,7 +69,7 @@ protected function replaceIsolatedDiffTags()
6969 {
7070 $ this ->oldIsolatedDiffTags = $ this ->createIsolatedDiffTagPlaceholders ($ this ->oldWords );
7171 $ this ->newIsolatedDiffTags = $ this ->createIsolatedDiffTagPlaceholders ($ this ->newWords );
72-
72+
7373 }
7474
7575 protected function createIsolatedDiffTagPlaceholders (&$ words )
@@ -191,25 +191,28 @@ protected function processDeleteOperation($operation, $cssClass)
191191 $ this ->insertTag ( "del " , $ cssClass , $ text );
192192 }
193193
194- protected function diffElements ($ oldText , $ newText )
194+ protected function diffElements ($ oldText , $ newText, $ stripWrappingTags = true )
195195 {
196- $ pattern = '/(^<[^>]+>)|(<\/[^>]+>$)/i ' ;
197- $ matches = array ();
198196 $ wrapStart = '' ;
199197 $ 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 );
204209 }
205- $ oldText = preg_replace ($ pattern , '' , $ oldText );
206- $ newText = preg_replace ($ pattern , '' , $ newText );
207210
208211 $ diff = new HtmlDiff ($ oldText , $ newText , $ this ->encoding , $ this ->specialCaseTags , $ this ->groupDiffs );
209212
210213 return $ wrapStart . $ diff ->build () . $ wrapEnd ;
211214 }
212-
215+
213216 protected function diffList ($ oldText , $ newText )
214217 {
215218 $ diff = new ListDiff ($ oldText , $ newText , $ this ->encoding , $ this ->specialCaseTags , $ this ->groupDiffs );
@@ -220,13 +223,13 @@ protected function processEqualOperation($operation)
220223 {
221224 $ result = array ();
222225 foreach ($ this ->newWords as $ pos => $ s ) {
223-
226+
224227 if ($ pos >= $ operation ->startInNew && $ pos < $ operation ->endInNew ) {
225228 if (in_array ($ s , $ this ->isolatedDiffTags ) && isset ($ this ->newIsolatedDiffTags [$ pos ])) {
226-
229+
227230 $ oldText = implode ("" , $ this ->findIsolatedDiffTagsInOld ($ operation , $ pos ));
228231 $ newText = implode ("" , $ this ->newIsolatedDiffTags [$ pos ]);
229-
232+
230233 if ($ this ->isListPlaceholder ($ s )) {
231234 $ result [] = $ this ->diffList ($ oldText , $ newText );
232235 } else {
@@ -239,7 +242,7 @@ protected function processEqualOperation($operation)
239242 }
240243 $ this ->content .= implode ( "" , $ result );
241244 }
242-
245+
243246 protected function isListPlaceholder ($ text )
244247 {
245248 if (in_array ($ text , array (
@@ -249,7 +252,7 @@ protected function isListPlaceholder($text)
249252 ))) {
250253 return true ;
251254 }
252-
255+
253256 return false ;
254257 }
255258
0 commit comments