Skip to content

Commit

Permalink
Merge branch 'v5' into develop-v5
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Oct 19, 2024
2 parents 34a3504 + d2d820c commit cff3c4c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/models/ImgTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ public function render(): Markup
if ($this->loadingStrategy !== 'eager') {
$attrs = $this->swapLazyLoadAttrs($this->loadingStrategy, $this->placeholder, $attrs);
}
// Remove any empty attributes
$attrs = array_filter($attrs);

// Remove any empty attributes except the alt attribute
$attrs = array_filter($attrs, function($value, $key) {
// Keep the 'alt' attribute even if it's empty
return $key === 'alt' || !empty($value);
}, ARRAY_FILTER_USE_BOTH);

// Render the tag
$tag = Html::tag('img', '', $attrs);

Expand Down
9 changes: 7 additions & 2 deletions src/models/PictureTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,13 @@ public function render(): Markup
if ($this->loadingStrategy !== 'eager') {
$attrs = $this->swapLazyLoadAttrs($this->loadingStrategy, $this->placeholder, $attrs);
}
// Remove any empty attributes
$attrs = array_filter($attrs);

// Remove any empty attributes except the alt attribute
$attrs = array_filter($attrs, function($value, $key) {
// Keep the 'alt' attribute even if it's empty
return $key === 'alt' || !empty($value);
}, ARRAY_FILTER_USE_BOTH);

// Render the tag
$content .= Html::tag('img', '', $attrs);
// Handle the <picture> tag
Expand Down

0 comments on commit cff3c4c

Please sign in to comment.