Skip to content

Commit 6342b02

Browse files
authored
Add a placeholder for the HTML5 picture element (#115)
1 parent de416bc commit 6342b02

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Diff for: lib/Caxy/HtmlDiff/HtmlDiff.php

+24
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ protected function diffIsolatedPlaceholder($operation, $pos, $placeholder, $stri
333333
return $this->diffElementsByAttribute($oldText, $newText, 'href', 'a');
334334
} elseif ($this->isImagePlaceholder($placeholder)) {
335335
return $this->diffElementsByAttribute($oldText, $newText, 'src', 'img');
336+
} elseif ($this->isPicturePlaceholder($placeholder)) {
337+
return $this->diffPicture($oldText, $newText);
336338
}
337339

338340
return $this->diffElements($oldText, $newText, $stripWrappingTags);
@@ -393,6 +395,23 @@ protected function diffTables($oldText, $newText)
393395
return $diff->build();
394396
}
395397

398+
/**
399+
* @param string $oldText
400+
* @param string $newText
401+
*
402+
* @return string
403+
*/
404+
protected function diffPicture($oldText, $newText) {
405+
if ($oldText !== $newText) {
406+
return sprintf(
407+
'%s%s',
408+
$this->wrapText($oldText, 'del', 'diffmod'),
409+
$this->wrapText($newText, 'ins', 'diffmod')
410+
);
411+
}
412+
return $this->diffElements($oldText, $newText);
413+
}
414+
396415
protected function diffElementsByAttribute($oldText, $newText, $attribute, $element)
397416
{
398417
$oldAttribute = $this->getAttributeFromTag($oldText, $attribute);
@@ -475,6 +494,11 @@ public function isImagePlaceholder($text)
475494
return $this->isPlaceholderType($text, 'img');
476495
}
477496

497+
public function isPicturePlaceholder($text)
498+
{
499+
return $this->isPlaceholderType($text, 'picture');
500+
}
501+
478502
/**
479503
* @param string $text
480504
* @param array|string $types

Diff for: lib/Caxy/HtmlDiff/HtmlDiffConfig.php

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class HtmlDiffConfig
5050
'a' => '[[REPLACE_A]]',
5151
'img' => '[[REPLACE_IMG]]',
5252
'pre' => '[[REPLACE_PRE]]',
53+
'picture' => '[[REPLACE_PICTURE]]',
5354
);
5455

5556
/**

0 commit comments

Comments
 (0)