Skip to content

Commit

Permalink
Update Parsedown.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Jul 24, 2024
1 parent 723c394 commit e78bf69
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/Converter/Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ protected function inlineImage($Excerpt)

// converts image to formats and put them in picture > source
if (
\count($formats = ((array) $this->config->get('pages.body.images.formats') ?? ['webp'])) > 0
\count($formats = ((array) $this->config->get('pages.body.images.formats') ?? [])) > 0
&& \in_array($InlineImage['element']['attributes']['src']['subtype'], ['image/jpeg', 'image/png', 'image/gif'])
) {
try {
Expand Down Expand Up @@ -427,20 +427,22 @@ protected function inlineImage($Excerpt)
],
];
}
$picture = [
'extent' => $InlineImage['extent'],
'element' => [
'name' => 'picture',
'handler' => 'elements',
'attributes' => [
'title' => $image['element']['attributes']['title'],
if (count($sources) > 0) {
$picture = [
'extent' => $InlineImage['extent'],
'element' => [
'name' => 'picture',
'handler' => 'elements',
'attributes' => [
'title' => $image['element']['attributes']['title'],
],
],
],
];
$picture['element']['text'] = $sources;
unset($image['element']['attributes']['title']); // @phpstan-ignore unset.offset
$picture['element']['text'][] = $image['element'];
$image = $picture;
];
$picture['element']['text'] = $sources;
unset($image['element']['attributes']['title']); // @phpstan-ignore unset.offset
$picture['element']['text'][] = $image['element'];
$image = $picture;
}
} catch (\Exception $e) {
$this->builder->getLogger()->debug($e->getMessage());
}
Expand Down

0 comments on commit e78bf69

Please sign in to comment.