Skip to content

Commit

Permalink
Add a placeholder for the HTML5 picture element (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeLeber authored Nov 5, 2023
1 parent de416bc commit 6342b02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/Caxy/HtmlDiff/HtmlDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ protected function diffIsolatedPlaceholder($operation, $pos, $placeholder, $stri
return $this->diffElementsByAttribute($oldText, $newText, 'href', 'a');
} elseif ($this->isImagePlaceholder($placeholder)) {
return $this->diffElementsByAttribute($oldText, $newText, 'src', 'img');
} elseif ($this->isPicturePlaceholder($placeholder)) {
return $this->diffPicture($oldText, $newText);
}

return $this->diffElements($oldText, $newText, $stripWrappingTags);
Expand Down Expand Up @@ -393,6 +395,23 @@ protected function diffTables($oldText, $newText)
return $diff->build();
}

/**
* @param string $oldText
* @param string $newText
*
* @return string
*/
protected function diffPicture($oldText, $newText) {
if ($oldText !== $newText) {
return sprintf(
'%s%s',
$this->wrapText($oldText, 'del', 'diffmod'),
$this->wrapText($newText, 'ins', 'diffmod')
);
}
return $this->diffElements($oldText, $newText);
}

protected function diffElementsByAttribute($oldText, $newText, $attribute, $element)
{
$oldAttribute = $this->getAttributeFromTag($oldText, $attribute);
Expand Down Expand Up @@ -475,6 +494,11 @@ public function isImagePlaceholder($text)
return $this->isPlaceholderType($text, 'img');
}

public function isPicturePlaceholder($text)
{
return $this->isPlaceholderType($text, 'picture');
}

/**
* @param string $text
* @param array|string $types
Expand Down
1 change: 1 addition & 0 deletions lib/Caxy/HtmlDiff/HtmlDiffConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class HtmlDiffConfig
'a' => '[[REPLACE_A]]',
'img' => '[[REPLACE_IMG]]',
'pre' => '[[REPLACE_PRE]]',
'picture' => '[[REPLACE_PICTURE]]',
);

/**
Expand Down

0 comments on commit 6342b02

Please sign in to comment.