Less home code more F3

This commit is contained in:
julien
2026-03-29 01:49:25 +01:00
parent 1c8c22e12c
commit ed6321e8f3
31 changed files with 346 additions and 189 deletions

View File

@@ -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;
}