Less home code more F3
This commit is contained in:
@@ -28,7 +28,9 @@ class MarkdownService extends Prefab
|
||||
// Résout les images media:filename et supprime les images externes.
|
||||
private static function resolveImages(string $html, Media $media): string
|
||||
{
|
||||
return preg_replace_callback('/<img\s[^>]*>/i', function (array $m) use ($media): string {
|
||||
$f3 = Base::instance();
|
||||
|
||||
return preg_replace_callback('/<img\s[^>]*>/i', function (array $m) use ($f3, $media): string {
|
||||
if (!preg_match('/src="([^"]*)"/', $m[0], $s) || !str_starts_with($s[1], 'media:')) {
|
||||
return '';
|
||||
}
|
||||
@@ -50,12 +52,21 @@ class MarkdownService extends Prefab
|
||||
$alt = $a[1];
|
||||
}
|
||||
if ($alt === '') {
|
||||
$alt = Base::instance()->encode($item['alt']);
|
||||
$alt = $f3->encode($item['alt']);
|
||||
}
|
||||
|
||||
$url = Base::instance()->encode($item['url']);
|
||||
$url = $f3->encode($item['url']);
|
||||
$attrs = 'src="' . $url . '" alt="' . $alt . '"';
|
||||
|
||||
return '<img src="' . $url . '" alt="' . $alt . '" loading="lazy" decoding="async">';
|
||||
// width/height préviennent le layout shift au chargement.
|
||||
if ((int) $item['width'] > 0) {
|
||||
$attrs .= ' width="' . (int) $item['width'] . '"';
|
||||
}
|
||||
if ((int) $item['height'] > 0) {
|
||||
$attrs .= ' height="' . (int) $item['height'] . '"';
|
||||
}
|
||||
|
||||
return '<img ' . $attrs . ' loading="lazy" decoding="async">';
|
||||
}, $html) ?? $html;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user