Skip to content

Commit 084747e

Browse files
committed
Merge pull request #23 from caxy/diff-update-no-tag-attribute-stripping
Updated list diff class to maintain the tags on lists.
2 parents c7d60bd + 1ac73ba commit 084747e

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

lib/Caxy/HtmlDiff/ListDiff.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ class ListDiff extends HtmlDiff
8585
* @var array
8686
*/
8787
protected $diffOrderIndex = array();
88+
89+
/**
90+
* This is the opening ol,ul,dl ist tag.
91+
* @var string
92+
*/
93+
protected $oldParentTag;
94+
95+
/**
96+
* This is the opening ol,ul,dl ist tag.
97+
* @var string
98+
*/
99+
protected $newParentTag;
88100

89101
/**
90102
* We're using the same functions as the parent in build() to get us to the point of
@@ -232,10 +244,12 @@ protected function formatList(array $arrayData, $index = 'old')
232244
array_key_exists($closingTag, $this->isolatedDiffTags)
233245
) {
234246
if ($index == 'new' && $this->isOpeningTag($arrayData[0])) {
247+
$this->newParentTag = $arrayData[0];
235248
$this->newListType = $this->getAndStripTag($arrayData[0]);
236249
}
237250

238251
if ($index == 'old' && $this->isOpeningTag($arrayData[0])) {
252+
$this->oldParentTag = $arrayData[0];
239253
$this->oldListType = $this->getAndStripTag($arrayData[0]);
240254
}
241255

@@ -448,13 +462,13 @@ protected function diff()
448462
if ($oldMatch && $oldMatch['new'] === null) {
449463
$newList = '';
450464
$oldList = $this->getListByMatch($oldMatch, 'old');
451-
$this->content .= $this->addListElementToContent($newList, $oldList, $oldMatch);
465+
$this->content .= $this->addListElementToContent($newList, $oldList, $oldMatch, $index, 'old');
452466
}
453467

454468
$match = $this->getArrayByColumnValue($this->textMatches, 'new', $index['position']);
455469
$newList = $this->childLists['new'][$match['new']];
456470
$oldList = $this->getListByMatch($match, 'old');
457-
$this->content .= $this->addListElementToContent($newList, $oldList, $match);
471+
$this->content .= $this->addListElementToContent($newList, $oldList, $match, $index, 'new');
458472
}
459473

460474
if ($index['type'] == 'content') {
@@ -471,7 +485,7 @@ protected function diff()
471485
if ($oldMatch && $oldMatch['new'] === null) {
472486
$newList = '';
473487
$oldList = $this->getListByMatch($oldMatch, 'old');
474-
$this->content .= $this->addListElementToContent($newList, $oldList, $oldMatch);
488+
$this->content .= $this->addListElementToContent($newList, $oldList, $oldMatch, $oldIndex, 'old');
475489
}
476490
} else {
477491
$this->content .= $this->addContentElementsToContent($oldKey);
@@ -490,11 +504,12 @@ protected function diff()
490504
* @param string $newList
491505
* @param string $oldList
492506
* @param array $match
507+
* @param array $index
493508
* @return string
494509
*/
495-
protected function addListElementToContent($newList, $oldList, array $match)
510+
protected function addListElementToContent($newList, $oldList, array $match, array $index, $type)
496511
{
497-
$content = "<li>";
512+
$content = $this->list[$type][$index['index']];
498513
$content .= $this->processPlaceholders(
499514
$this->diffElements(
500515
$this->convertListContentArrayToString($oldList),
@@ -768,7 +783,12 @@ protected function indexLists()
768783
*/
769784
protected function addListTypeWrapper($opening = true)
770785
{
771-
return "<" . (!$opening ? "/" : '') . $this->listType . ">";
786+
787+
if ($opening) {
788+
return $this->newParentTag ?: $this->oldParentTag;
789+
} else {
790+
return "<" . (!$opening ? "/" : '') . $this->listType . ">";
791+
}
772792
}
773793

774794
/**

0 commit comments

Comments
 (0)