Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions lib/Caxy/HtmlDiff/ListDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ class ListDiff extends HtmlDiff
* @var array
*/
protected $diffOrderIndex = array();

/**
* This is the opening ol,ul,dl ist tag.
* @var string
*/
protected $oldParentTag;

/**
* This is the opening ol,ul,dl ist tag.
* @var string
*/
protected $newParentTag;

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

if ($index == 'old' && $this->isOpeningTag($arrayData[0])) {
$this->oldParentTag = $arrayData[0];
$this->oldListType = $this->getAndStripTag($arrayData[0]);
}

Expand Down Expand Up @@ -448,13 +462,13 @@ protected function diff()
if ($oldMatch && $oldMatch['new'] === null) {
$newList = '';
$oldList = $this->getListByMatch($oldMatch, 'old');
$this->content .= $this->addListElementToContent($newList, $oldList, $oldMatch);
$this->content .= $this->addListElementToContent($newList, $oldList, $oldMatch, $index, 'old');
}

$match = $this->getArrayByColumnValue($this->textMatches, 'new', $index['position']);
$newList = $this->childLists['new'][$match['new']];
$oldList = $this->getListByMatch($match, 'old');
$this->content .= $this->addListElementToContent($newList, $oldList, $match);
$this->content .= $this->addListElementToContent($newList, $oldList, $match, $index, 'new');
}

if ($index['type'] == 'content') {
Expand All @@ -471,7 +485,7 @@ protected function diff()
if ($oldMatch && $oldMatch['new'] === null) {
$newList = '';
$oldList = $this->getListByMatch($oldMatch, 'old');
$this->content .= $this->addListElementToContent($newList, $oldList, $oldMatch);
$this->content .= $this->addListElementToContent($newList, $oldList, $oldMatch, $oldIndex, 'old');
}
} else {
$this->content .= $this->addContentElementsToContent($oldKey);
Expand All @@ -490,11 +504,12 @@ protected function diff()
* @param string $newList
* @param string $oldList
* @param array $match
* @param array $index
* @return string
*/
protected function addListElementToContent($newList, $oldList, array $match)
protected function addListElementToContent($newList, $oldList, array $match, array $index, $type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this function is also called on line 465 but it doesn't have these new arguments, which would cause an error.

https://github.com/caxy/php-htmldiff/blob/diff-update-no-tag-attribute-stripping/lib/Caxy/HtmlDiff/ListDiff.php#L465

{
$content = "<li>";
$content = $this->list[$type][$index['index']];
$content .= $this->processPlaceholders(
$this->diffElements(
$this->convertListContentArrayToString($oldList),
Expand Down Expand Up @@ -768,7 +783,12 @@ protected function indexLists()
*/
protected function addListTypeWrapper($opening = true)
{
return "<" . (!$opening ? "/" : '') . $this->listType . ">";

if ($opening) {
return $this->newParentTag ?: $this->oldParentTag;
} else {
return "<" . (!$opening ? "/" : '') . $this->listType . ">";
}
}

/**
Expand Down